SE_PROD;Cadastro de Produtos;sys_tbbrow; 8; 0;18;79;se_prod;;
:SKEL
VARIAVEL w_colsep := chr(179)
VARIAVEL w_headsep := chr(196)
VARIAVEL zrecn := recn()
VARIAVEL zOrdSetFocus:=OrdSetFocus()

VARIAVEL zbTamCom = #TEXTO_FONTE
   Private zrecn,zPcod,zOrd
   if se_prod->peatual<=0
      Alert("O estoque total do produto esta zerado!",,"B/W")
   else
      Se_prod->(zRecn:=Recno(), zPcod:=pcod, zOrd:=DbSetOrder(1), Abra('0',R_SIGA,'SE_GREAT','SE_GREAT','SE_GREAT','Str(pcod,6)+Ptam+Pcor'), Se_Great->( Brow_Db('SE_GREAT'), DbCloseArea()), se_prod->(DbGoTo(zRecn),DbSetOrder(zOrd)) )
   endif
#FIM_TEXTO_FONTE

VARIAVEL zbLotes = #TEXTO_FONTE
   Private zrecn,zPcod,zOrd
   if se_prod->peatual<=0
      Alert("O estoque total do produto esta zerado!",,"B/W")
   else
      Se_prod->(zRecn:=Recno(), zPcod:=pcod, zOrd:=DbSetOrder(1), Brw_Lotes_1Prd(zPcod, "pselote2"), se_prod->(DbGoTo(zRecn),DbSetOrder(zOrd)) )
   endif
#FIM_TEXTO_FONTE

VARIAVEL zbComposicoesComInsumo = #TEXTO_FONTE
   Private zpCod:=Se_Prod->pCod, zpDesc:=Se_Prod->pDesc
   BrwComposicoes("ComposicoesComInsumo", zPcod)
#FIM_TEXTO_FONTE


VARIAVEL zbDelete = #TEXTO_FONTE
   Private m_pCod:=Se_Prod->pCod
   Abra('0',R_SIGA,'SE_GREAT','SE_GREAT','SE_GREAT','Str(pcod,6)+Ptam+Pcor')
   if DbSeek(Str(m_pCod,6))
      Alert("Esse produto nao pode ser deletado;pois possui tamanhos cadastrados!;",,"B/W") 
      Se_Great->(DbCloseArea())
      Return .f.
   EndIf
   Se_Great->(DbCloseArea())
   Abra("0NOIDX",R_SIGA,"SE_KITS","SE_KITS", "SE_KITS", "PCOD", "SE_KITS2", "PCODINSUMO") 
   If DbSeek(m_pCod)
      Alert("Esse produto nao pode ser deletado;pois ele tem insumos cadastrados!;",,"B/W") 
      SE_KITS->(DbCloseArea())
      Return .f.
   EndIf
   OrdSetFocus("SE_KITS2")
   If DbSeek(m_pCod)
      Alert("Esse produto nao pode ser deletado;pois ele eh insumo de outras composicoes!;",,"B/W") 
      SE_KITS->(DbCloseArea())
      Return .f.
   EndIf
   SE_KITS->(DbCloseArea())
   Abra("0",R_SIGA,"SE_GREDI","SE_GREDI","SE_GREDI","Str(pcod,6)+str(pedicao,15)+mfges")
   if DbSeek(Str(m_pCod,6))
      Alert("Esse produto nao pode ser deletado;pois possui edicoes cadastradas!;",,"B/W") 
      SE_GREDI->(DbCloseArea())
      Return .f.
   EndIf
   SE_GREDI->(DbCloseArea())

   Abra ("0",r_siga,"Se_Lotes","Se_Lotes","Se_Lotes","str(pcod,6)+cr_situaca+plote")
   if DbSeek(Str(m_pCod,6))
      Alert("Esse produto nao pode ser deletado;pois possui lotes cadastrados!;",,"B/W") 
      Se_Lotes->(DbCloseArea())
      Return .f.
   EndIf
   Se_Lotes->(DbCloseArea())
   DbSelectArea('se_prod')
   tb_del(d_ob)
#FIM_TEXTO_FONTE

VARIAVEL zbDesativa = {||d_ob:Inactive() , Alert("active? "+hb_valtoexp(d_ob:active) )}

VARIAVEL z_BlkEdi = #TEXTO_FONTE
   Private zTotConsig:=0, z_pcod, z_sele:=Select()
   Abra("0",R_SIGA,"SE_GREDI","SE_GREDI","SE_GREDI","Str(pcod,6)+str(pedicao,15)+mfges")
   (OrdScope(0,Str(z_pcod:=se_prod->pCod,6)) , OrdScope(1,Str(z_pcod:=se_prod->pCod,6)), DbGoTop() , debugalert(' Indexkey= '+Indexkey()))
   if pcod=se_prod->pCod .or. upper(se_prod->pconsig)$'SGC' 
      WHILE z_pcod=Pcod .and. .not. eof()
         zTotConsig += if(peatual>mqatend.and.mfges=" ",peatual,0)
         dbskip()
      ENDDO
      se se_prod->pEatual>zTotConsig entao SE_GREDI->( AppendBlank(), _field->pCod:=Se_Prod->pCod, _field->Mdata:=S_datual, _field->Peatual:=se_prod->pEatual-zTotConsig)
      DbGoTop()
      Brow_Db('SE_GREDI')
      zTotConsig := 0
      DbSeek(Str(z_pcod,6))
      WHILE z_pcod=Pcod .and. .not. eof()
         zTotConsig += if(peatual>mqatend.and.mfges=" ",peatual,0)
         dbskip()
      ENDDO
      se se_prod->pEatual>zTotConsig entao SE_GREDI->( AppendBlank(), _field->pCod:=Se_Prod->pCod, _field->Mdata:=S_datual, _field->Peatual:=se_prod->pEatual-zTotConsig)
   else
      Mensagem('O produto nao tem controle de estoque com compra consignada...',1)
   endif
   Se_GrEdi->(DbCloseArea())
   DbSelectArea(z_sele)
#FIM_TEXTO_FONTE

VARIAVEL zbOpenAll = #TEXTO_FONTE
   se select('sccpfab')=0  entao Abra("0NOIDX", r_siga, "sccpfab",  "sccpfab","sccpfab",  "cp_nome")
   se select('se_subd')=0  entao Abra("0NOIDX", r_siga, "se_subd" , "se_subd", "seisd_c", "sdcod")
   se select('se_divis')=0 entao Abra("0NOIDX", r_siga, "se_divis", "Se_divis")
   se select('se_prod')=0  entao Abra_Arq("se_prod",,zArea0,r_siga) senao DbSelectArea("se_prod")
   OrdSetFocus(zOrdSetFocus)
   dbgoto(zrecn)
#FIM_TEXTO_FONTE

/#Premio;Ppremio;N;999999;6;S;
// 32;Cibrow("SE_PRDLJ",,"SE_PRDL0");Barra-Lojas ;
// 22;upd_prod(1,"PROD_RAPIDA");R-Inclui Registro;
// 91;disp_sdse(se_prod->pref,"R");[-Dem_Ref ;
//Obs;pPedeObs;C;X;  1;;

variavel zbDiv:={|cpDivisao| Se_divis->( DbGoto(Val(Left(cpDivisao,2))), dDesc) }
variavel zbSubd:={|cpDivisao| Se_Subd->( DbSeek(cpDivisao), sdDesc) }
variavel zbFabr:={|nFabricante| sccpfab->( DbGoto(nFabricante), if(empty(cp_fantasi),cp_nome,cp_fantasi) ) }

variavel zBlObs:={||!empty(wpObs:=Compl_obs(pCod,pObs,'edit')).and.(RegLock(),_field->pObs:=wpObs,DbCommit(),DbUnlock())}
variavel znil:=eVal(zbOpenAll)
variavel zbAction:={|bFunction| zrecn:=Recno(), zOrdSetFocus:=OrdSetFocus(), eVal(bFunction), eVal(zbOpenAll), DobRefresh() }
variavel zbEdit:={|nSaldo,oC,fipos| nSaldo>=0.and.( RegLock(), _field->peAtual:=nSaldo, dbCommit(), dbUnlock(), .t.) }

VARIAVEL znAzul0:=16711680
VARIAVEL znAzul1:=10027008
VARIAVEL zAzul2:=16776960
VARIAVEL zW:=16777215
VARIAVEL zBlack:=0
VARIAVEL zRed:=255
VARIAVEL zGreen:=32768
VARIAVEL znCinza:=8421504
VARIAVEL zYellow:=65535
VARIAVEL zFgUsaCores:=(xGetEnv("USA_CORES_NO_BROWSE")="S")
variavel zbCor:={|| if(peAtual>0,{znAzul0,zW,zW,znAzul0},if(pEAtual=0,{zGreen,zW,zW,zGreen}, {zRed,zW,zW,zRed})) }

VARIAVEL zbClose:={|cAlias| Select(cAlias)>0 .and. ( (cAlias)->(DbCloseArea()), .t.) }
COMANDO SAIDA znil = ( eVal(zbClose,'Cp_Divis'), eVal(zbClose,'Cp_SubD'), eVal(zbClose,'sccpfab') )

variavel #TEXTO_FONTE
   if .not. xFile(r_siga+'ci_cest.dbf') 
      xDbCreateFromStr(r_siga+'ci_cest', {{'cest','C',7,0},{'ncm','C',8,0},{'descricao','M',10,0}})
      se_prod->(Abra("0NOIDX",r_siga,"ci_cest","ci_cest","ci_cest","cest"),ci_cest->(DbCloseArea()))
   endif
   //ONINIT
      if sys_segmento='mercados'
         hwg_TbFi(@D_oB, 'Cod Barras;Pdic6;N;99999999999999;14;S;')
         hwg_TbFi(@D_oB, 'Cod;PCOD;N;99999;5;N;')
         hwg_TbFi(@D_oB, 'Descricao;PDESC;C;@s40;40;S;')
      else
         if sys_segmento='oticas'
            hwg_TbFi(@D_oB, 'Ref.Fabr;Preffab;C;@S40;40;S;;')
            hwg_TbFi(@D_oB, 'Descricao;PDESC;C;@s40;37;S;')
         else
            hwg_TbFi(@D_oB, 'Descricao;PDESC;C;@s35;35;S;')
            se sFgContaPecas entao hwg_TbFi(@D_oB, 'Ref.Fabr;Preffab;C;@S8;8;S;;')
         endif
      endif
      hwg_TbFi(@D_oB, 'Un;PUNIDADE;C;xxxxx;  3;;')
      se sys_segmento='valegas'.or.xGetEnv("USA_EDICOES_OU_COMPRA_CONSIGNADA")="S" entao hwg_TbFi(@D_oB, 'Csg;pConsig;C;X; 3;;')
      if sFgIlhasEstoque
         se s_vb_numde>0 entao hwg_TbFi(@D_oB, 'Sld_Global;PEATUAL;N;999999.999;10;S;') senao hwg_TbFi(@D_oB, 'Sld_Global;PEATUAL;N;99999;5;S;')
         se s_vb_numde>0 entao hwg_TbFi(@D_oB, 'Ilha_'+lTrim(Str(sNumeroDaIlha,4))+';SaldoDisponivel(pCod,.t.);P;999999.999;10;N;') senao hwg_TbFi(@D_oB, 'Na_Ilha;SaldoDisponivel(pCod,.t.);P;99999;5;N;')
      else
         se s_vb_numde>0 entao hwg_TbFi(@D_oB, 'EAtual;PEATUAL;N;999999.999;10;S;zbCor;') senao hwg_TbFi(@D_oB, 'EAtual;PEATUAL;N;999999;6;S;zbCor;')
         // se s_vb_numde>0 entao hwg_TbFi(@D_oB, 'EAtual;PEATUAL;N;999999.999;10;S;') senao hwg_TbFi(@D_oB, 'EAtual;PEATUAL;N;99999;5;S;zbCor;;zbEdit;')
      endif
      // sNumeroDaIlha:=xGetEnv("ILHA_PADRAO_DE_ESTOQUE")      
      se sys_segmento='perfis' entao hwg_TbFi(@D_oB, 'eRef2;PEATx;N;99999;5;S;')
      if fieldpos('pcodncm')>0 
         hwg_TbFi(@D_oB, 'PorNcm?;pCodNcm;C;X;7;S;')
         hwg_TbFi(@D_oB, 'Apresentacao;pPrincipio;C;@S25;25;S;')
         hwg_TbFi(@D_oB, 'Ref.Fabr;Preffab;C;@S8;8;S;;')
         hwg_TbFi(@D_oB, 'Incond?;pAbatQtd;C;X;7;S;')
      endif
      se sys_segmento='farma' entao hwg_TbFi(@D_oB, 'PedeLote?;pPedeLote;C;X;9;S;')
      if sys_segmento='armas' 
         hwg_TbFi(@D_oB, 'Tipo Uso;tpArma;C;X;8;S;')
         hwg_TbFi(@D_oB, 'N.Serie;nSerie;C;@S9;9;S;')
         hwg_TbFi(@D_oB, 'N.Cano;nCano;C;@S9;9;S;')
         hwg_TbFi(@D_oB, 'Calibre, Marca, Capacidade, Tipo de funcionamento, Comprimento, etc.;Left(pObs,20);P;@S20;20;;')
      endif
      if sys_segmento='consig'
         hwg_TbFi(@D_oB, 'ContEdic;pconsig;C;x;8;S;')
         hwg_TbFi(@D_oB, 'SaldoCSG;PestConsig;N;999999999;9;S;')
         hwg_TbFi(@D_oB, 'Edicao;pedicao;N;99999;6;S;')
         hwg_TbFi(@D_oB, 'Period;pperiod;C;x;6;S;')      
         hwg_TbFi(@D_oB, 'RecebCSG;PestCsgRec;N;999999999;9;S;')
      endif
      if sys_segmento='combus'.or.sys_segmento='valegas'
         hwg_TbFi(@D_oB, 'Bico;Pbico;N;99999;4;S;')
         hwg_TbFi(@D_oB, 'CaixaBico?;Pcombustiv;C;!;10;S;')
         hwg_TbFi(@D_oB, 'Cod_ANP;pCodANP;C;999999999;9;S;')
      endif
      if fieldpos('pglp')>0
         hwg_TbFi(@D_oB, 'pGLP;pGLP;N;999.99;6;S;')
         hwg_TbFi(@D_oB, 'pGLn;pGNN;N;999.99;6;S;')
         hwg_TbFi(@D_oB, 'pGLi;pGNI;N;999.99;6;S;')
         hwg_TbFi(@D_oB, 'vPART p/KG;vPART;N;9999999.99;10;S;')
      endif
      if sFgContaPecas
         hwg_TbFi(D_oB, 'QPerfis;pPecas;N;99999;8;S;')
         hwg_TbFi(@D_oB, 'PrVenda;PVLUVENDA;N;9999.99;7;S;')
         hwg_TbFi(@D_oB, 'Prc Cust;PVLUVEN3;N;99999.99;  8;;')
         hwg_TbFi(D_oB, 'Pede_Perfis?;pContPecas;S;X;11;S;')
      endif
      if sys_segmento='locacao'
         hwg_TbFi(@D_oB, 'Div;PDIVISAO;C;9999;4;S;')
         hwg_TbFi(@D_oB, 'Divisao;eVal(zbDiv,pDivisao);P;@S15;15;N;')
         hwg_TbFi(@D_oB, 'SubDivisao;eVal(zbSubd,pDivisao);P;@S20;11;N;')
      endif
      if .not. sys_segmento='mercados'
         hwg_TbFi(@D_oB, 'Ref.Fabr;Preffab;C;@S8;8;S;;')
         hwg_TbFi(@D_oB, 'Cod;PCOD;N;999999;6;N;')
      endif
      se fieldpos('PCODSubPrd')>0 entao hwg_TbFi(@D_oB, 'SubPrd;PCODSubPrd;N;999999;6;N;')
      if !sFgContaPecas
         hwg_TbFi(@D_oB, 'PrVenda;PVLUVENDA;N;9999.99;7;S;')
         hwg_TbFi(@D_oB, 'Prc Cust;PVLUVEN3;N;99999.99;8;;')
         hwg_TbFi(@D_oB, 'Prc Sug.;PVLUsug;N;99999.99;8;S;')
      endif
      if xGetEnv("ATACADO")="S" 
      	hwg_TbFi(@D_oB, 'PrAtacado;pvluven4;N;9999.99;7;S;')
      	hwg_TbFi(@D_oB, 'PrInternet;pvluven5;N;9999.99;7;S;')
      endif
      if sys_segmento='bares' 
         hwg_TbFi(@D_oB, 'Cardapio;pFamilia;C;@S20;20;;')
         hwg_TbFi(@D_oB, 'SubD;PDIVISAO;C;9999;4;S;')
         // hwg_TbFi(@D_oB, 'Divisao;eVal(zbDiv,pDivisao);P;@S10;10;N;')
         hwg_TbFi(@D_oB, 'SubDivisao;eVal(zbSubd,pDivisao);P;@S20;20;N;')
      endif
      se fieldpos('pobs')>0 entao hwg_TbFi(@D_oB, 'Obs;Left(pObs,20);P;@S20;20;;')
      hwg_TbFi(@D_oB, 's;pServico;C;X;  1;;')
      hwg_TbFi(@D_oB, 'o;pPedeObs;C;X;  1;;')
      hwg_TbFi(@D_oB, 'G;Pgpreco;C;X;  1;;')
      hwg_TbFi(@D_oB, 'Tp;Ptipoitem;C;99;2;S;')
      hwg_TbFi(@D_oB, 'Finalidade;Efd_TipoItem();P;@S13;13;N;')
      hwg_TbFi(@D_oB, 'Fabr;PPRINCFORN;N;9999;6;S;')
      hwg_TbFi(@D_oB, 'Nome Fabricante;eval(zbFabr,PPRINCFORN);P;@S20; 20;N;')
      if sys_segmento='calcados'
         hwg_TbFi(@D_oB, 'Grade;pGrade;C;@s5;5;S;')
         hwg_TbFi(@D_oB, 'Faixa Tam;pTam;C;@s10;11;S;')
         hwg_TbFi(@D_oB, 'Tipo;Ptipo;C;@S5;5;S;')
         hwg_TbFi(@D_oB, 'Marca/Fabric;Pref;C;@S10;10;S;')
         hwg_TbFi(@D_oB, 'Modelo;pmarcamode;C;@s10;11;S;')
      endif
      hwg_TbFi(@D_oB, 'PesoBru Gr;pPesoBru;N;99999; 10;S;')
      hwg_TbFi(@D_oB, 'PesoLiq Gr;pPesoLiq;N;99999; 6;S;')
      hwg_TbFi(@D_oB, 'Fracao;PITENS;N;9999;  4;;')
      hwg_TbFi(@D_oB, 'CSTicm;nf_csticm;C;999;6;S;')
      hwg_TbFi(@D_oB, 'CF;pcategoria;C;!!!;2;S;')
      hwg_TbFi(@D_oB, 'NCM;pCodClaFis;N;99999999;8;;')
      se fieldpos('pcest')>0 entao hwg_TbFi(@D_oB, 'CEST;pCEST;C;9999999;7;;')
      hwg_TbFi(@D_oB, 'CFOP;pcfop;C;9x999;5;S;')
      se .not. sys_segmento='mercados' entao hwg_TbFi(@D_oB, 'Cod Barras;Pdic6;N;99999999999999;14;S;')
      se sys_segmento<>'valegas' entao hwg_TbFi(@D_oB, 'Csg;pConsig;C;X; 3;;')
      if sys_segmento<>'locacao'.and.sys_segmento<>'bares'
         hwg_TbFi(@D_oB, 'Div;PDIVISAO;C;9999;4;S;')
         hwg_TbFi(@D_oB, 'Divisao;eVal(zbDiv,pDivisao);P;@S15;15;N;')
         hwg_TbFi(@D_oB, 'SubDivisao;eVal(zbSubd,pDivisao);P;@S20;20;N;')
      endif
      se sys_segmento='mercados' entao hwg_TbFi(@D_oB, 'Ref.Fabr;Preffab;C;@S8;8;S;;')
      hwg_TbFi(@D_oB, 'DataPrec;Pdataalter;D;;10;S;')
      hwg_TbFi(@D_oB, '%Dsc;Pdesconto;N;999.99;6;;')
      hwg_TbFi(@D_oB, '%Prm;Pdescprom;N;999.99;6;;')
      hwg_TbFi(@D_oB, '%IPI;Pipient;N;999.99;6;S;')
      hwg_TbFi(@D_oB, 'AvalMin;pAvalMin;N;99999.99;  8;S;')
      hwg_TbFi(@D_oB, 'E_Contr;PEATx;N;9999999;  7;;')
      hwg_TbFi(@D_oB, 'EMin;PEMIN;N;999999;  6;;')
      hwg_TbFi(@D_oB, 'E Max;PEMAX;N;999999;  6;;')
      hwg_TbFi(@D_oB, 'CO;PCODORI;N;9;  1;;')
      hwg_TbFi(@D_oB, 'L Prc;PFGLPRE;C;x;  1;;')
      hwg_TbFi(@D_oB, 'Em Prom;PFGPROM;C;x;  1;;')
   //ENDONINIT
   //ONDLGINIT
         se sFgIlhasEstoque entao Pf_MovimentaIlha(,, "RECALCULA_SALDOS", .t.)
         oDlg:Maximize()
   //ENDDLGINIT
#FIM_TEXTO_FONTE
:TBMT
22;eval(zbAction,{||upd_prod(1,"PROD_T1")});Ins-Inclui ;
22;eval(zbAction,{||upd_prod(1,"PROD_T1",,.t.)});Ins-Duplica ;Ins-Duplica Dados da Ficha do Produto;prd_cadastra.ico;;;;;Duplica;;;
13;eval(zbAction,{||se_doget(D_ob)});Enter-Edita ;
7;eval(zbAction,{||Eval(zbDelete)});Del-Apaga ;
65;eval(zbAction,{||tb_update(D_OB)});A-Altera ;
69;eval(zbAction,{||ext_screen(pcod,pdatabal)});E-Extrato ;
47;eval(zbAction,{||Eval(zbTamCom)});/-Subitens ;
92,sys_segmento="farma".or.sFgControlaProducao;eVal(zbAction,zbLotes);\-Lotes ;
93;eval(zbAction,{||disp_sdse(pcod)});]-Demanda ;
71;eval(zbAction,{||DispEnt(pcod)});G-Compras ;
80;tb_pesq(D_OB);P-Pesquisa Chave;
70;tb_filter(d_ob);F-Filtra ;
84;tb_locate(D_oB);T-Busca_Trecho ;
76;tb_locate(D_oB);L-Busca_Iniciais ;
67;tb_locate(D_oB);C-Repete_Busca ;
82;doget(D_ob,,.t.);R-Repete_Edicao ;
79;tb_index(D_OB);O-Ordena ;
73;eval(zbAction,{||lst_alias(D_OB)});I-Imprime ;
61;doget(D_ob,,.t.);=-Repete_Edicao ;
92,sys_segmento="consig";eVal(zbAction,z_BlkEdi);\-Edicoes ;
92,fieldpos('pobs')>0;eVal(zbAction,zBlObs);M-Observacoes ;
48,sFgIlhasEstoque;eVal(zbAction,{||Pf_MovimentaIlha(,, "RECALCULA_SALDOS", .t.)});0-Tot_Ilhas ;
85;eval(zbAction,zbComposicoesComInsumo);U-Comp_Com_Insumo ;U-Composicoes com o Insumo;;;;;;U-Comps;;;
86;eval(zbAction,{||upd_prod("TrocaTextoNaDescricaoDoProduto")});V-TrocaNomes;V-Troca textos na descricao do produto;;;;;;V-TrocaTxt;;;
87;eval(zbAction,{||upd_prod("ColocarFabricante")});W-PoeFabr;W-Coloca Fabricante na Ficha se Zerado;;;;;;W-TrocaFabr;;;
90;eval(zbAction,{||upd_prod("TrocarFabricante")});Z-TrocaFabr;Z-Troca Fabricante do produto;;;;;;Z-TrocaFabr;;;
86,sys_segmento="calcados";eval(zbAction,{||upd_prod("AgruparTamanhos")});U-Agrupar;U-Agrupar tamanhos de um produto com os de outro;;;;;;U-Agrupar;;;
