AddPed.aph 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990
  1. <%
  2. /**** Pagina de login do site ****/
  3. Local cLCodLogin := ""
  4. if type ("cCodLogin") <> "U"
  5. cLCodLogin := cCodLogin
  6. Endif
  7. %>
  8. <!DOCTYPE html>
  9. <html class="fixed sidebar-left-collapsed">
  10. <head>
  11. <!-- Basic -->
  12. <meta charset="iso-8859-1">
  13. <link rel="shortcut icon" href="images/favicon.png" type="image/x-icon" />
  14. <title><%=cTitle%></title>
  15. <meta name="keywords" content="<%=cTitle%>" />
  16. <meta name="description" content="<%=cTitle%>">
  17. <meta name="author" content="SMSTI">
  18. <meta http-equiv="Chache-Control" content="no-cache" />
  19. <meta http-equiv="Expires" content="0" />
  20. <meta http-equiv="Pragma" content="no-cache" />
  21. <!-- Mobile Metas -->
  22. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  23. <!-- Web Fonts -->
  24. <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800|Shadows+Into+Light" rel="stylesheet" type="text/css">
  25. <!-- Vendor CSS -->
  26. <link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.css" />
  27. <link rel="stylesheet" href="assets/vendor/font-awesome/css/font-awesome.css" />
  28. <link rel="stylesheet" href="assets/vendor/magnific-popup/magnific-popup.css" />
  29. <link rel="stylesheet" href="assets/vendor/bootstrap-datepicker/css/bootstrap-datepicker3.css" />
  30. <link rel="stylesheet" href="assets/vendor/bootstrap-select/css/bootstrap-select.min.css" />
  31. <style>
  32. body .btn {
  33. white-space: nowrap !important;
  34. display: inline;
  35. overflow-y: hidden;
  36. }
  37. </style>
  38. <!-- Specific Page Vendor CSS -->
  39. <link rel="stylesheet" href="assets/vendor/select2/css/select2.css" />
  40. <link rel="stylesheet" href="assets/vendor/select2-bootstrap-theme/select2-bootstrap.min.css" />
  41. <link rel="stylesheet" href="assets/vendor/jquery-datatables-bs3/assets/css/datatables.css" />
  42. <link rel="stylesheet" href="assets/vendor/bootstrap-fileupload/bootstrap-fileupload.min.css" />
  43. <link rel="stylesheet" href="assets/vendor/pnotify/pnotify.custom.css" />
  44. <!-- Theme CSS -->
  45. <link rel="stylesheet" href="assets/stylesheets/theme.css" />
  46. <!-- Skin CSS -->
  47. <link rel="stylesheet" href="assets/stylesheets/skins/default.css" />
  48. <!-- Theme Custom CSS -->
  49. <link rel="stylesheet" href="assets/stylesheets/theme-custom.css">
  50. <!-- Head Libs -->
  51. <script src="assets/vendor/modernizr/modernizr.js"></script>
  52. <script src="assets/vendor/style-switcher/style.switcher.localstorage.js"></script>
  53. <style>
  54. .flexContainer {
  55. display: flex;
  56. }
  57. .smsediticon {
  58. flex: 1;
  59. }
  60. .btedit { /* margem e largura da imagem */
  61. margin-left: -45px;
  62. width: 47px;
  63. }
  64. </style>
  65. </head>
  66. <body>
  67. <section class="body">
  68. <!-- start: header -->
  69. <header class="header">
  70. <%=cHeader%>
  71. </header>
  72. <!-- end: header -->
  73. <div class="inner-wrapper">
  74. <!-- start: sidebar -->
  75. <aside id="sidebar-left" class="sidebar-left">
  76. <div class="sidebar-header">
  77. <div class="sidebar-title">
  78. Menu
  79. </div>
  80. <div class="sidebar-toggle hidden-xs" data-toggle-class="sidebar-left-collapsed" data-target="html" data-fire-event="sidebar-left-toggle">
  81. <i class="fa fa-bars" aria-label="Toggle sidebar"></i>
  82. </div>
  83. </div>
  84. <div class="nano">
  85. <div class="nano-content">
  86. <nav id="menu" class="nav-main" role="navigation">
  87. <ul class="nav nav-main">
  88. <%=cMenus%>
  89. </ul>
  90. </nav>
  91. </div>
  92. <script>
  93. // Maintain Scroll Position
  94. if (typeof localStorage !== 'undefined') {
  95. if (localStorage.getItem('sidebar-left-position') !== null) {
  96. var initialPosition = localStorage.getItem('sidebar-left-position'),
  97. sidebarLeft = document.querySelector('#sidebar-left .nano-content');
  98. sidebarLeft.scrollTop = initialPosition;
  99. }
  100. }
  101. </script>
  102. </div>
  103. </aside>
  104. <!-- end: sidebar -->
  105. <section role="main" class="content-body">
  106. <header class="page-header">
  107. <h2><%=cPagina%></h2>
  108. <div class="right-wrapper pull-right">
  109. </div>
  110. </header>
  111. <!-- start: page -->
  112. <section class="panel">
  113. <!-- <header class="panel-heading">
  114. </header> -->
  115. <div class="panel-body">
  116. <div class="row">
  117. <div class="col-lg-12">
  118. <section class="panel form-wizard" id="w9">
  119. <form action = "" method="post" class="form-horizontal" id="formOrc">
  120. <div class="tabs">
  121. <ul class="nav nav-tabs nav-justify">
  122. <li class="active">
  123. <a href="#orc-informar" data-toggle="tab" class="text-center">Pedido</a>
  124. </li>
  125. <!--
  126. <li class="">
  127. <a href="#orc-anexos" data-toggle="tab" class="text-center">Anexos</a>
  128. </li>
  129. -->
  130. </ul>
  131. <div class="tab-content">
  132. <div id="orc-informar" class="tab-pane active">
  133. <!--
  134. <%=cVendedor%>
  135. -->
  136. <!-- linha 0: dados do Pedido -->
  137. <%=cFilOrc%>
  138. <%=cCodOrc%>
  139. <div class="mb-md hidden-lg hidden-xl"></div>
  140. <div class="mb-md hidden-lg hidden-xl"></div>
  141. <!-- linha 1: dados da empresa -->
  142. <div class="row form-group">
  143. <div class="col-lg-6">
  144. <label class="control-label">Cliente
  145. <span class="required">*</span>
  146. </label>
  147. <%=cCliente%>
  148. </div>
  149. <div class="col-lg-3">
  150. <label class="control-label">Tipo de Cliente</label>
  151. <%=cTpCliente%>
  152. </div>
  153. <div class="col-lg-3">
  154. <label class="control-label">Grupo de Tributação</label>
  155. <%=cGrpTrib%>
  156. </div>
  157. <!-- <div class="col-lg-1">
  158. <label class="control-label">Revisão</label>
  159. <%=cRevOpt%>
  160. </div> -->
  161. </div>
  162. <!-- linha 3: input -->
  163. <div class="row form-group">
  164. <div class="col-lg-5" style="display:none;">
  165. <label class="control-label">Tabela de Preço</label>
  166. <%=cTabela%>
  167. </div>
  168. </div>
  169. <!-- linha 4 input -->
  170. <div class="row form-group">
  171. <div class="col-lg-6">
  172. <label class="control-label">Cliente de Entrega
  173. <span class="required">*</span>
  174. </label>
  175. <%=cCliEntr%>
  176. </div>
  177. <div class="col-lg-6">
  178. <label class="control-label">Local de Entrega</label>
  179. <%=cLocalEnt%>
  180. </div>
  181. </div>
  182. <div class="row form-group">
  183. <div class="col-lg-1">
  184. <label class="control-label">CEP Entrega
  185. </label>
  186. <%=cEndCep%>
  187. </div>
  188. <div class="col-lg-5">
  189. <label class="control-label">Endereço
  190. </label>
  191. <%=cEndRua%>
  192. </div>
  193. <div class="col-lg-1">
  194. <label class="control-label">Número
  195. </label>
  196. <%=cEndNum%>
  197. </div>
  198. <div class="col-lg-2">
  199. <label class="control-label">Bairro
  200. </label>
  201. <%=cEndBair%>
  202. </div>
  203. <div class="col-lg-2">
  204. <label class="control-label">Município
  205. </label>
  206. <%=cEndMun%>
  207. </div>
  208. <div class="col-lg-1">
  209. <label class="control-label">UF
  210. </label>
  211. <%=cEndUF%>
  212. </div>
  213. <div class="col-lg-6">
  214. <label class="control-label">Referência
  215. </label>
  216. <%=cEndRef%>
  217. </div>
  218. <%=cEndOpc%>
  219. </div>
  220. <!-- linha 5 input -->
  221. <!-- <div class="row form-group">
  222. <div class="col-lg-6">
  223. <label class="control-label">Obra
  224. <span class="required">*</span>
  225. </label>
  226. <%=cObra%>
  227. </div>
  228. <div class="col-lg-3">
  229. <label class="control-label">Status da Obra
  230. <span class="required">*</span>
  231. </label>
  232. <%=cStatusObra%>
  233. </div>
  234. <div class="col-lg-3">
  235. <label class="control-label">Previsão de Fechamento
  236. <span class="required">*</span>
  237. </label>
  238. <%=cPrevFecha%>
  239. </div>
  240. </div> -->
  241. <!-- linha 6 input -->
  242. <div class="row form-group">
  243. <div class="col-lg-3">
  244. <label class="control-label">Condição de Pagamento
  245. <span class="required">*</span>
  246. </label>
  247. <%=cCondPag%>
  248. </div>
  249. <div class="col-lg-3">
  250. <label class="control-label">Regional
  251. <span class="required">*</span>
  252. </label>
  253. <%=cRegional%>
  254. </div>
  255. <div class="col-lg-3">
  256. <span class="required">*</span>
  257. <label class="control-label">T. Oper. Lum</label>
  258. <%=cOperLum%>
  259. </div>
  260. <div class="col-lg-3">
  261. <label class="control-label">Tipo de Frete</label>
  262. <span class="required">*</span>
  263. <%=cTpFrete%>
  264. </div>
  265. <!-- <div class="col-lg-6">
  266. <label class="control-label">Intermediador</label>
  267. <%=cIntermed%>
  268. </div> -->
  269. <!-- <div class="col-lg-2">
  270. <label class="control-label">Retorno</label>
  271. <%=cRetorno%>
  272. </div> -->
  273. </div>
  274. <!-- linha 7 input -->
  275. <div class="row form-group">
  276. <div class="col-lg-6">
  277. <label class="control-label">Transportadora</label>
  278. <%=cTransp%>
  279. </div>
  280. <div class="col-lg-6">
  281. <label class="control-label">Redespacho</label>
  282. <%=cRedesp%>
  283. </div>
  284. </div>
  285. <!-- linha 7 input -->
  286. <div class="row form-group">
  287. <!-- <div class="col-lg-2">
  288. <label class="control-label">Estudo Luminotécnico
  289. <span class="required">*</span>
  290. </label>
  291. <%=cEstudo%>
  292. </div> -->
  293. <!-- <div class="col-lg-2">
  294. <label class="control-label">Num. Estudo</label>
  295. <%=cNumEst%>
  296. </div> -->
  297. <!-- <div class="col-lg-3">
  298. <label class="control-label">Segmento
  299. <span class="required">*</span>
  300. </label>
  301. <%=cSegmento%>
  302. </div> -->
  303. <!-- <div class="col-lg-2">
  304. <label class="control-label">Prospecção</label>
  305. <%=cProsp%>
  306. </div>
  307. <div class="col-lg-3">
  308. <label class="control-label">Prospectado Por</label>
  309. <%=cProspPor%>
  310. </div> -->
  311. </div>
  312. <!-- linha 9: input -->
  313. <div class="row form-group">
  314. <div class="col-lg-2">
  315. <label class="control-label">Valor do Frete</label>
  316. <%=cValFre%>
  317. </div>
  318. <div class="col-lg-2">
  319. <label class="control-label">Data Entrega</label>
  320. <%=cEntrega%>
  321. </div>
  322. <div class="col-lg-2">
  323. <label class="control-label">Fat. Parcial</label>
  324. <%=cFatPar%>
  325. </div>
  326. <div class="col-lg-6">
  327. <label class="control-label">Negociadora
  328. <span class="required">*</span>
  329. </label>
  330. <%=cNegociad%>
  331. </div>
  332. </div>
  333. <!-- linha 8: input -->
  334. <div class="row form-group">
  335. <div class="col-lg-4">
  336. <label class="control-label">Vendedor 2
  337. <span class="required">*</span>
  338. </label>
  339. <%=cVend2%>
  340. </div>
  341. <div class="col-lg-4">
  342. <label class="control-label">Vendedor 3</label>
  343. <%=cVend3%>
  344. </div>
  345. <div class="col-lg-4">
  346. <label class="control-label">Vendedor 4</label>
  347. <%=cVend4%>
  348. </div>
  349. </div>
  350. <!-- linha 10: input -->
  351. <div class="row form-group">
  352. <!-- <div class="col-lg-2">
  353. <label class="control-label">Validade</label>
  354. <%=cValidade%>
  355. </div> -->
  356. <!-- <div class="col-lg-2">
  357. <label class="control-label">Prazo de Embarque</label>
  358. <%=cPrazoEmb%>
  359. </div> -->
  360. <!-- <div class="col-lg-2">
  361. <label class="control-label">% Frete
  362. </label>
  363. <%=cPFrete%>
  364. </div> -->
  365. <div class="col-lg-4">
  366. <label class="control-label">Usuário Emissão</label>
  367. <%=cUsuEmiss%>
  368. </div>
  369. <div class="col-lg-1">
  370. <label class="control-label">Estágio PV</label>
  371. <%=cEstagPv%>
  372. </div>
  373. <%=cNumOp%>
  374. <div class="col-lg-4">
  375. <label class="control-label">Email NF</label>
  376. <%=cMailNf%>
  377. </div>
  378. </div>
  379. <div class="row form-group">
  380. <div class="col-lg-4">
  381. <label class="control-label">Data Emissão</label>
  382. <%=cEmissao%>
  383. </div>
  384. <div class="col-lg-1">
  385. <label class="control-label">PV Envio PB</label>
  386. <%=cEnvpb%>
  387. </div>
  388. <%=cNumOrc%>
  389. <div class="col-lg-2">
  390. <label class="control-label">% RT</label>
  391. <%=cComRT%>
  392. </div>
  393. <%=cMargemCont%>
  394. </div>
  395. <div class="row form-group">
  396. <div class="col-md-4">
  397. <label class="control-label">Justificativa Atraso</label>
  398. <textarea class="form-control" rows="3" data-plugin-maxlength="" maxlength="50" id="C5_JUS" name="C5_JUS" disabled><%=cJust%></textarea>
  399. </div>
  400. <div class="col-md-4">
  401. <label class="control-label">Mensagem Nota</label>
  402. <textarea class="form-control" rows="3" data-plugin-maxlength="" maxlength="250" id="C5_MENNOTA" name="C5_MENNOTA" <%=Iif(!lEdit,'disabled','')%>><%=cMenNota%></textarea>
  403. </div>
  404. <div class="col-md-4">
  405. <label class="control-label">Mensagem Nota 1</label>
  406. <textarea class="form-control" rows="3" data-plugin-maxlength="" maxlength="250" id="C5_MENNOT1" name="C5_MENNOT1" <%=Iif(!lEdit,'disabled','')%>><%=cMenNota%></textarea>
  407. </div>
  408. <div class="col-md-4">
  409. <label class="control-label">Mensagem Nota 2</label>
  410. <textarea class="form-control" rows="3" data-plugin-maxlength="" maxlength="250" id="C5_MENNOT2" name="C5_MENNOT2" <%=Iif(!lEdit,'disabled','')%>><%=cMenNota%></textarea>
  411. </div>
  412. <div class="col-md-4">
  413. <label class="control-label">Mensagem Nota 3</label>
  414. <textarea class="form-control" rows="3" data-plugin-maxlength="" maxlength="250" id="C5_MENNOT3" name="C5_MENNOT3" <%=Iif(!lEdit,'disabled','')%>><%=cMenNota%></textarea>
  415. </div>
  416. <div class="col-md-4">
  417. <label class="control-label">Descrição para Faturamento</label>
  418. <textarea class="form-control" rows="3" data-plugin-maxlength="" maxlength="10" id="C5_DESCFAT" name="C5_DESCFAT" <%=Iif(!lEdit,'disabled','')%>><%=cDesFat%></textarea>
  419. </div>
  420. </div>
  421. <!-- linha 11 input -->
  422. <!-- <div class="row form-group">
  423. <div class="col-md-4">
  424. <label class="control-label" for="textareaDefault">Observação Comercial</label>
  425. <textarea class="form-control" rows="3" data-plugin-maxlength="" maxlength="240" id="C5_OBS" name="C5_OBS" <%=Iif(!lEdit,'disabled','')%>><%=cObsCom%></textarea>
  426. </div>
  427. <div class="col-md-4">
  428. <label class="control-label" for="textareaDefault">Comentário</label>
  429. <textarea class="form-control" rows="3" data-plugin-maxlength="" maxlength="240" id="C5_COMENT" name="C5_COMENT" <%=Iif(!lEdit,'disabled','')%>><%=cComent%></textarea>
  430. </div>
  431. </div> -->
  432. <br>
  433. <br>
  434. <!-- tabela com os produtos do Pedido -->
  435. <div class="table-responsive" id="ItensOrc" style="overflow-x:visible">
  436. <section class="panel">
  437. <header class="panel-heading">
  438. <h2 class="panel-title">Itens do Pedido</h2>
  439. </header>
  440. <table style="width:100%" class="table table-bordered table-striped mb-none table-hover table-condensed display nowrap" id="datatable-editable" aria-describedby="datatable-details_info">
  441. <thead>
  442. <tr>
  443. <%=cOrcCabec%>
  444. </tr>
  445. </thead>
  446. <tbody>
  447. <%=cOrcItens%>
  448. </tbody>
  449. </table>
  450. </section>
  451. </div>
  452. <br>
  453. <!-- botões com ações na tabela dos itens -->
  454. <%=cBtnItens%>
  455. <br>
  456. <br>
  457. <!-- Totais -->
  458. <div class="col-lg-13">
  459. <section class="panel">
  460. <header class="panel-heading">
  461. <h2 class="panel-title">Totais do Pedido</h2>
  462. </header>
  463. <div class="panel-body">
  464. <div class="form-inline" align="center">
  465. <div class="row">
  466. <!-- <%=cTotalReg%> -->
  467. <br />
  468. <div class="col-sm-12">
  469. <label class="">Itens&nbsp;</label>
  470. <input class="form-control text-right" id="TOTAL_ITENS" name="TOTAL_ITENS" placeholder="0,00" disabled="" type="text" value=<%=Transform(nTVlrUnit,"@E 999,999,999,999.99")%>></input>
  471. &nbsp;&nbsp;&nbsp;&nbsp;
  472. <label class="">Impostos&nbsp;</label>
  473. <input class="form-control text-right" id="TOTAL_IMP" name="TOTAL_IMP" placeholder="0,00" disabled="" type="text" value=<%=Transform(nTImpostos,"@E 999,999,999,999.99")%>></input>
  474. <!-- &nbsp;&nbsp;&nbsp;&nbsp;
  475. <label class="">Frete&nbsp;</label>
  476. <input class="form-control text-right" id="TOTAL_FRETE" name="TOTAL_FRETE" placeholder="0,00" disabled="" type="text" value=<%=Transform(nTFrete,"@E 999,999,999,999.99")%>></input>
  477. -->
  478. &nbsp;&nbsp;&nbsp;&nbsp;
  479. <label class="text-weight-extrabold">Total&nbsp;</label>
  480. <input class="form-control text-right text-weight-bold" id="TOTAL_ORC" name="TOTAL_ORC" placeholder="0,00" disabled="" type="text" value=<%=Transform(nTTotal,"@E 999,999,999,999.99")%>></input>
  481. </div>
  482. </div>
  483. <br>
  484. <!--
  485. <div class="row">
  486. <div class="col-sm-12">
  487. <label class="">Desconto&nbsp;</label>
  488. <input class="form-control text-right" id="TOTAL_ACRESC" name="TOTAL_ACRESC" placeholder="0,00" disabled="" type="text" value=<%=Transform(nTAcresc,"@E 999,999,999,999.99")%>></input>
  489. <label class="">Total&nbsp;</label>
  490. <input class="form-control text-right" id="TOTAL_ORC" name="TOTAL_ORC" placeholder="0,00" disabled="" type="text" value=<%=Transform(nTTotal,"@E 999,999,999,999.99")%>></input>
  491. </div>
  492. </div>
  493. <div class="row">
  494. <div class="col-sm-12">
  495. <label class="">Comissão Prevista&nbsp;</label>
  496. <input class="form-control text-right" id="TOTAL_COM" name="TOTAL_COM" placeholder="0,00" disabled="" type="text" value=<%=Transform(nTComiss,"@E 999,999,999,999.99")%>></input>
  497. </div>
  498. </div>
  499. -->
  500. </div>
  501. </div>
  502. </section>
  503. </div>
  504. <br>
  505. <br>
  506. <div class="row form-group" align="center">
  507. <%=cBotoes%>
  508. </div>
  509. </div>
  510. <!-- aba de anexos
  511. <div id="orc-anexos" class="tab-pane">
  512. <div class="form-group">
  513. <label class="col-md-3 control-label">Anexar: </label>
  514. <div class="col-md-9">
  515. <div class="fileupload fileupload-new" data-provides="fileupload">
  516. <div class="input-append">
  517. <div class="uneditable-input">
  518. <i class="fa fa-file fileupload-exists"></i>
  519. <span class="fileupload-preview"></span>
  520. </div>
  521. <span class="btn btn-default btn-file">
  522. <span class="fileupload-exists">Selecionar</span>
  523. <span class="fileupload-new">Arquivo</span>
  524. <input type="file" name="anexo" id="anexo" />
  525. </span>
  526. <a href="#" id="btnOrcUpload" class="btn btn-default fileupload-exists" data-dismiss="fileupload">Gravar</a>
  527. </div>
  528. </div>
  529. </div>
  530. </div>
  531. <div class="row mg-files" data-sort-destination data-sort-id="media-gallery" id="OrcAnexos">
  532. <%=cAnexos%>
  533. </div>
  534. </div>
  535. -->
  536. </div>
  537. </div>
  538. </form>
  539. </section>
  540. </div>
  541. </div>
  542. </div>
  543. </section>
  544. <div class="modal fade" id="dialogCusto" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
  545. <div class="modal-dialog">
  546. <div class="modal-content">
  547. <div class="modal-header">
  548. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  549. <h4 class="modal-title" id="myModalLabel">Custo e Preço de Venda do Produto</h4>
  550. </div>
  551. <div class="modal-body">
  552. <label class="control-label">Valor de Venda Unitário</label>
  553. <input id="VLRVENDA" name="VLRVENDA" class="form-control money text-right" placeholder="0,00" value="">
  554. <input type="hidden" id="itemAtu"/>
  555. <br>
  556. <label class="control-label">Valor do Custo Unitário</label>
  557. <input id="CUSTO" name="CUSTO" class="form-control money text-right" placeholder="0,00" value="">
  558. </div>
  559. <div class="modal-footer">
  560. <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
  561. <button type="button" class="btn btn-primary" onclick="javascript:gravaCusto( $('#itemAtu').val(),$('#VLRVENDA').val(),$('#CUSTO').val() );">Confirmar</button>
  562. </div>
  563. </div>
  564. </div>
  565. </div>
  566. <div class="modal fade" id="dialogEntrega" tabindex="-1" role="dialog" aria-labelledby="basicModal" aria-hidden="true">
  567. <div class="modal-dialog">
  568. <div class="modal-content">
  569. <div class="modal-header">
  570. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  571. <h4 class="modal-title" id="myModalLabel">Local de Entrega</h4>
  572. </div>
  573. <div class="modal-body">
  574. <div class="row form-group">
  575. <div class="col-md-8">
  576. <label class="control-label">Estado</label>
  577. <select data-plugin-selectTwo data-live-search="false" id="UF_ENTREGA" name="UF_ENTREGA" class="form-control poulate placeholder mb-md" style="width: 400px;" data-plugin-options='{"placeholder":"Selecione um estado"}' onchange="javascript:getMunEnt($('#UF_ENTREGA').val());">
  578. <%=cOptUF%>
  579. </select>
  580. </div>
  581. </div>
  582. <div class="row form-group">
  583. <div class="col-md-8">
  584. <label class="control-label">Município</label>
  585. <select data-plugin-selectTwo data-live-search="true" id="MUN_ENTREGA" name="MUN_ENTREGA" class="form-control poulate placeholder mb-md" style="width: 400px;" data-plugin-options='{"placeholder":"Selecione um município"}' disabled>
  586. <%=cOptMun%>
  587. </select>
  588. </div>
  589. </div>
  590. </div>
  591. <div class="modal-footer">
  592. <br>
  593. <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
  594. <button type="button" class="btn btn-primary" onclick="javascript:gravaEntrega( $('#UF_ENTREGA').val(),$('#MUN_ENTREGA').val() );">Confirmar</button>
  595. </div>
  596. </div>
  597. </div>
  598. </div>
  599. <div style="display:none;">
  600. <form action="U_OrcUpload.apw?PR=<%=cLCodLogin%>" method="post" id="frmOrcUpload" enctype="multipart/form-data">
  601. <input type="hidden" name="dirOrc" value="<%=cDirOrc%>" />
  602. </form>
  603. </div>
  604. <footer class="panel-footer text-right">
  605. Desenvolvido por <img src="images/sms.png"/>
  606. </footer>
  607. </div>
  608. </section>
  609. <!-- end: page -->
  610. <div id="dialogRemover" class="modal-block mfp-hide">
  611. <section class="panel">
  612. <header class="panel-heading">
  613. <h2 class="panel-title">Exclusão da linha</h2>
  614. </header>
  615. <div class="panel-body">
  616. <div class="modal-wrapper">
  617. <div class="modal-text">
  618. <p>Confirma a exclusão desta linha?</p>
  619. </div>
  620. </div>
  621. </div>
  622. <footer class="panel-footer">
  623. <div class="row">
  624. <div class="col-md-12 text-right">
  625. <button id="dialogConfirm" class="btn btn-primary">Confirma</button>
  626. <button id="dialogCancel" class="btn btn-default">Cancela</button>
  627. </div>
  628. </div>
  629. </footer>
  630. </section>
  631. </div>
  632. <div id="modalSuccess" class="modal-block modal-block-success mfp-hide">
  633. <section class="panel">
  634. <header class="panel-heading">
  635. <h2 class="panel-title">Success!</h2>
  636. </header>
  637. <div class="panel-body">
  638. <div class="modal-wrapper">
  639. <div class="modal-icon">
  640. <i class="fa fa-check"></i>
  641. </div>
  642. <div class="modal-text">
  643. <h4>Success</h4>
  644. <p>This is a successfull message.</p>
  645. </div>
  646. </div>
  647. </div>
  648. <footer class="panel-footer">
  649. <div class="row">
  650. <div class="col-md-12 text-right">
  651. <button class="btn btn-success modal-dismiss">OK</button>
  652. </div>
  653. </div>
  654. </footer>
  655. </section>
  656. </div>
  657. <!-- Vendor -->
  658. <script src="assets/vendor/jquery/jquery.js"></script>
  659. <script src="assets/vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
  660. <script src="assets/vendor/bootstrap/js/bootstrap.js"></script>
  661. <script src="assets/vendor/nanoscroller/nanoscroller.js"></script>
  662. <script src="assets/vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
  663. <script src="assets/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.pt-BR.min.js"></script>
  664. <script src="assets/vendor/magnific-popup/jquery.magnific-popup.js"></script>
  665. <script src="assets/vendor/jquery-placeholder/jquery-placeholder.js"></script>
  666. <script src="assets/vendor/fuelux/js/spinner.js"></script>
  667. <!-- Custom -->
  668. <script src="custom/js/bootbox.js"></script>
  669. <script src="custom/js/moeda.js"></script>
  670. <!-- Specific Page Vendor -->
  671. <script src="assets/vendor/select2/js/select2.js"></script>
  672. <script src="assets/vendor/jquery-datatables/media/js/jquery.dataTables.js"></script>
  673. <script src="assets/vendor/jquery-datatables/extras/TableTools/js/dataTables.tableTools.min.js"></script>
  674. <script src="assets/vendor/jquery-datatables-bs3/assets/js/datatables.js"></script>
  675. <script src="assets/vendor/jquery-datatables/media/js/jquery.dataTables.js"></script>
  676. <script src="assets/vendor/bootstrap-maxlength/bootstrap-maxlength.js"></script>
  677. <script src="assets/vendor/autosize/autosize.js"></script>
  678. <script src="assets/vendor/bootstrap-fileupload/bootstrap-fileupload.min.js"></script>
  679. <script src="assets/vendor/pnotify/pnotify.custom.js"></script>
  680. <script src="assets/vendor/bootstrap-select/bootstrap-select.min.js"></script>
  681. <!-- Theme Base, Components and Settings -->
  682. <script src="assets/javascripts/theme.js"></script>
  683. <!-- Theme Initialization Files -->
  684. <script src="assets/javascripts/theme.init.js"></script>
  685. <!-- Theme Custom -->
  686. <script src="assets/javascripts/theme.custom.js"></script>
  687. <script src="custom/js/jquery.maskMoney.js"></script>
  688. <script src="custom/js/portalMask.js"></script>
  689. <script type="text/javascript">
  690. var tblDesc = [];
  691. var optProd = '<%=cOptProd%>';
  692. var optCond = '<%=cOptCond%>';
  693. var optCli = '<%=cOptCli%>';
  694. /**
  695. Desabilita o enter na pagina
  696. **/
  697. $(function () {
  698. $('form').bind("keypress", function (e) {
  699. if (e.keyCode == 13) return false;
  700. });
  701. });
  702. //Remove as opções da tabela e adiciona o scroll
  703. $(document).ready(function () {
  704. $('#datatable-editable').DataTable({
  705. "scrollX": true,
  706. "ordering": false,
  707. "searching": false,
  708. "paging": false,
  709. "autoWidth": false,
  710. "info": false
  711. });
  712. $('.dataTables_length').addClass('.w-auto'); //ajusta o tamanho das colunas automaticamente
  713. });
  714. //Formata campos de moeda
  715. $(function() {
  716. //$('#iC6_PRCVEN01').maskMoney({thousands:'.', decimal:','});
  717. $('.myformato').maskMoney({thousands:'.', decimal:','});
  718. $('.percentual').maskMoney({thousands:'.', decimal:',', suffix:'%',allowNegative:true});
  719. })
  720. function formate() {
  721. $('.myformato').maskMoney({thousands:'.', decimal:','});
  722. $('.percentual').maskMoney({thousands:'.', decimal:',', suffix:'%',allowNegative:true});
  723. }
  724. <%=cTblDesc%>
  725. function sleep(ms) {
  726. return new Promise(resolve => setTimeout(resolve, ms));
  727. }
  728. //Manipulando as colunas
  729. function ocultaColumn (colIndex) {
  730. var table = document.getElementById('datatable-editable');
  731. for (var r = 0; r < table.rows.length; r++)
  732. table.rows[r].cells[colIndex].style.display = 'none';
  733. }
  734. function mostraColumn (colIndex) {
  735. var table = document.getElementById('datatable-editable');
  736. for (var r = 0; r < table.rows.length; r++)
  737. table.rows[r].cells[colIndex].style.display = '';
  738. }
  739. /**
  740. Monta a tela para selecionar o cliente
  741. **/
  742. function getCliente(btPesquisa){
  743. var cCliBusca = $("#C5_CLIENTE").val().toUpperCase();
  744. // Usando a função buscarProdutos com um callback
  745. buscarClientes(cCliBusca, function (clientesEncontrados) {
  746. if (clientesEncontrados.length >= 1) {
  747. var selectOptions = '<select id="clienteSelecionado">';
  748. var indiceHifen;
  749. var selOptions = '';
  750. clientesEncontrados.forEach(function (cliente) {
  751. selectOptions += "<option value='" + cliente + "'>" + cliente + "</option>";
  752. });
  753. selectOptions += "</select>";
  754. bootbox.dialog({
  755. title: 'Clientes',
  756. message: "<p>Selecione o cliente desejado:</p>" + selectOptions,
  757. backdrop: false,
  758. size: 'large',
  759. buttons: {
  760. confirm: {
  761. label: 'Confirmar',
  762. className: 'btn-primary',
  763. callback: function () {
  764. var clienteSelecionado = $("#clienteSelecionado").val();
  765. // Atualiza o campo original com o produto escolhido
  766. $("#C5_CLIENTE").val(clienteSelecionado);
  767. clienteSelecionado = formataCli(clienteSelecionado);
  768. SelCliente(clienteSelecionado);
  769. }
  770. },
  771. cancel: {
  772. label: 'Cancelar',
  773. className: 'btn-default',
  774. callback: function () {
  775. }
  776. }
  777. }
  778. });
  779. }
  780. });
  781. }
  782. /**
  783. Monta a tela para selecionar o local de entrega
  784. **/
  785. function getEntrega(btEntrega){
  786. $("#dialogEntrega").modal('show');
  787. }
  788. /**
  789. Busca as cidades do estado selecionado
  790. **/
  791. function getMunEnt(estado){
  792. if(estado==""){
  793. bootbox.alert("Selecione um estado para continuar!")
  794. } else {
  795. $.ajax({
  796. url: "U_GetMunUF.apw?PR=<%=cLCodLogin%>",
  797. type: "POST",
  798. data: 'uf='+estado,
  799. cache: false,
  800. success: function(retorno){
  801. if (retorno.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  802. $("html").html(retorno);
  803. return;
  804. }
  805. if(retorno==""){
  806. bootbox.alert("Falha ao localizar os municípios, tente novamente!");
  807. return;
  808. }
  809. //Preenche o select das cidades
  810. document.getElementById('MUN_ENTREGA').innerText = null;
  811. $("#MUN_ENTREGA").append(retorno);
  812. $("#MUN_ENTREGA").removeAttr('disabled');
  813. $(document).trigger('cidadesCarregadas');
  814. }
  815. });
  816. }
  817. }
  818. /**
  819. Função para gravar o local de entrega no campo em tela
  820. **/
  821. function gravaEntrega(estado,mun){
  822. $('#C5_UFENT').val(estado+mun);
  823. $("#dialogEntrega").modal('hide');
  824. //busca o percentual de frete
  825. atuVlrFrete();
  826. }
  827. /**
  828. Função para formatar o código do cliente
  829. **/
  830. function formataCli(cli){
  831. var indiceHifen = 0;
  832. if(cli != ""){
  833. // Encontra a posição do primeiro h?fen na string
  834. indiceHifen = cli.indexOf("-");
  835. //Pega apenas o codigo do cliente
  836. if(indiceHifen > 0){
  837. cli = cli.substring(0, indiceHifen);
  838. }
  839. //Remove espaços vazios
  840. cli = cli.replace("/","").trim();
  841. }
  842. return cli
  843. }
  844. /**
  845. Função para formatar o código do produto
  846. **/
  847. function formataProd(prod){
  848. var indiceHifen = 0;
  849. if(prod != ""){
  850. // Encontra a posição do primeiro hífen na string
  851. indiceHifen = prod.indexOf("--");
  852. //Pega apenas o codigo do produto
  853. if(indiceHifen > 0){
  854. prod = prod.substring(0, indiceHifen);
  855. }
  856. //Remove espaços vazios
  857. prod = prod.trim();
  858. }
  859. return prod
  860. }
  861. /**
  862. Funcao excutada ao selecionar o cliente
  863. **/
  864. function SelCliente(cliente){
  865. var lOK = false;
  866. var dialogCli = bootbox.dialog({
  867. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Buscando dados do cliente. Aguarde...</p>',
  868. closeButton: false
  869. });
  870. cliente = cliente.replace('/',"");
  871. //Verifica se cliente tem títulos em atraso
  872. $.ajax({
  873. url: "U_PGetSitCli.apw?PR=<%=cLCodLogin%>",
  874. type: "POST",
  875. data: 'cliente='+cliente,
  876. cache: false,
  877. success: function(data){
  878. dialogCli.modal('hide');
  879. if (data.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  880. $("html").html(data);
  881. return;
  882. }
  883. aCli = data.split('|#|');
  884. if (aCli[1] != "" && aCli[1] != "::" && aCli[1].toUpperCase().indexOf("EXPIRES") == -1) {
  885. var dialog = bootbox.dialog({
  886. title: 'Mensagem do Cliente',
  887. message: "<p>"+aCli[1]+"</p>",
  888. backdrop: true,
  889. buttons: {
  890. ok: {
  891. label: "OK"
  892. }
  893. }
  894. });
  895. }
  896. //cliente bloqueado para comprar
  897. if (aCli[0] == "0"){
  898. //Bloqueia os campos para impossibilitar continuar a inclusão
  899. atuModoCpo('B')
  900. } else {
  901. //Desbloqueia os campos
  902. atuModoCpo('D')
  903. $("#select2-C5_TIPOCLI-container").html($("#C5_TIPOCLI option[value='"+aCli[2]+"']").html());
  904. $("#C5_TIPOCLI").val(aCli[2]);
  905. $("#C5_GRPTRIB").val(aCli[3]);
  906. if (aCli[4] != ""){
  907. $("#C5_CONDPAG").val(aCli[4]);
  908. $("#select2-C5_CONDPAG-container").html($("#C5_CONDPAG option[value='"+aCli[4]+"']").html());
  909. }
  910. $("#C5_CONDPAG").removeAttr('disabled');
  911. $("#C5_UFENT").val(aCli[5]);
  912. $("#C5_VEND").val(aCli[6]);
  913. $("#select2-C5_VEND-container").html($("#C5_VEND option[value='"+aCli[6]+"']").html());
  914. //Adiciona as opções do cliente
  915. if($("#C5_CLIENT")[0].options.length <= 1){
  916. $("#C5_CLIENT").append($.parseHTML(optCli));
  917. }
  918. $('.selectpicker').selectpicker('render');
  919. $('.selectpicker').selectpicker('refresh');
  920. //na alteração já traz o select preenchido
  921. if($("#C5_CLIENT")[0].options.length <= 1){
  922. $("#C5_CLIENT").append($.parseHTML(optCli));
  923. }
  924. //$('.selectpicker').selectpicker('render');
  925. //$('.selectpicker').selectpicker('refresh');
  926. //$('#C5_CLIENT').selectpicker('val', cliente);
  927. $('#C5_CLIENT').val(cliente).select2();
  928. $('#C5_CLIENT').trigger('change')
  929. $("#C5_NROPOR").focus();
  930. }
  931. }
  932. });
  933. }
  934. /**
  935. Atualiza o modo de edição do campo
  936. **/
  937. function atuModoCpo(cTipo){
  938. var aCampos = ["C5_CLIENTE","C5_XCONTAT","C5_XCONDDD","C5_XCONTEL","C5_CLIENT","C5_OBRA","C5_VEND6","C5_TERMOME","C5_CONDPAG","C5_RETORNO",/*"CJ_LUMINOT","CJ_SEGMENT","C5_PROPECC"*/"C5_VEND1","C5_VEND2","C5_VEND3","C5_VEND4","C5_CODESP","C5_NEGOCIA","C5_VALIDA","C5_PRZEMB","C5_TPFRETE","C5_FRETE","C5_OBS","C6_PRODUTO01","btEndEntrega", "C5_DATENTR","C5_TPFRETE", "C5_FATPARC", "C5_ESTAGIO", "C5_MAILNF", "C5_SIBAP", "C5_FRETE", "C5_TRANSP", "C5_REDESP", "C5_MENNOTA", "C5_MENNOT1", "C5_MENNOT2" , "C5_MENNOT3" , "C5_DESCFAT", "C5_ENDOPC", "C5_CEPOPC","C5_RUAOPC","C5_NUMOPC","C5_BAIROPC","C5_MUNOPC","C5_UFOPC","C5_REFOPC" , "C5_TIPOLUM", "C5_COMENT"]; //"C5_UFENT",
  939. var nI = 0;
  940. //Atualiza os campos
  941. for (nI = 0; nI < (aCampos.length) ; nI++) {
  942. if(cTipo == 'B'){
  943. $("#"+aCampos[nI]).attr("disabled","");
  944. } else {
  945. $("#"+aCampos[nI]).removeAttr('disabled');
  946. $("#"+aCampos[nI]).attr("disabled",false);
  947. }
  948. }
  949. }
  950. /**
  951. Atualiza o endereço de entrega ao mudar o cliente de entrega
  952. **/
  953. function atuLocEnt(){
  954. var cliEntrega = $("#C5_CLIENT").val();
  955. var dialogCli = bootbox.dialog({
  956. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Buscando dados do cliente. Aguarde...</p>',
  957. closeButton: false
  958. });
  959. if(cliEntrega != ""){
  960. $.ajax({
  961. url: "U_GetCliEnd.apw?PR=<%=cLCodLogin%>",
  962. type: "POST",
  963. data: 'cliente='+cliEntrega,
  964. cache: false,
  965. success: function(retorno){
  966. dialogCli.modal('hide');
  967. if (retorno.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  968. $("html").html(retorno);
  969. return;
  970. }
  971. aVlr = retorno.substr(3).split('|#|');
  972. $("#C5_UFENT").val(aVlr[0]+aVlr[1]);
  973. $("#UF_ENTREGA").val(aVlr[0]).select2();
  974. $("#C5_CEPOPC").val(aVlr[5]);
  975. $("#C5_RUAOPC").val(aVlr[2].split(',')[0]);
  976. $("#C5_NUMOPC").val(aVlr[2].split(',')[1]);
  977. $("#C5_BAIROPC").val(aVlr[4]);
  978. $("#C5_MUNOPC").val(aVlr[3]);
  979. $("#C5_UFOPC").val(aVlr[0]);
  980. $("#C5_REFOPC").val(aVlr[6]);
  981. $("#UF_ENTREGA").trigger('change')
  982. // Escuta o evento que indica que as cidades foram carregadas
  983. $(document).on('cidadesCarregadas', function () {
  984. $("#MUN_ENTREGA")
  985. .val(aVlr[0] + ' - ' + aVlr[1].trim())
  986. .select2();
  987. });
  988. }
  989. });
  990. }
  991. }
  992. /**
  993. Preenche a revisão da oportunidade
  994. **/
  995. function atuRevOpt(){
  996. var cOport = $("#C5_NROPOR").val();
  997. var cobjOport = $("#C5_NROPOR")[0];
  998. var cRevisa = cobjOport.options[cobjOport.selectedIndex].text.substr(7,2)
  999. var dialog = bootbox.dialog({
  1000. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Buscando dados da oportunidade... Aguarde...</p>',
  1001. closeButton: false
  1002. });
  1003. if(cOport != ""){
  1004. // $("#C5_REVISA").val(cRevisa);
  1005. $.ajax({
  1006. url: "U_GetDadosOpt.apw?PR=<%=cLCodLogin%>",
  1007. data: 'oportunidade='+cOport+'&revisao='+cRevisa,
  1008. type: "POST",
  1009. async: false,
  1010. success:
  1011. function(dados) {
  1012. if (dados.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  1013. $("html").html(dados);
  1014. return;
  1015. } else {
  1016. if (dados.substr(0, 2) == "OK") {
  1017. aVlr = dados.substr(5).split('|#|');
  1018. //Atualiza a comissão
  1019. $("#C5_COMISTR").val(aVlr[0]);
  1020. //Atualiza o vendedor
  1021. $("#C5_VEND3").append($.parseHTML(aVlr[1]));
  1022. $('.selectpicker').selectpicker('render');
  1023. $('.selectpicker').selectpicker('refresh');
  1024. $("#select2-C5_VEND3-container").html($("#C5_VEND3 option[value='"+aVlr[2]+"']").html());
  1025. } else {
  1026. bootbox.alert("Falha ao localizar os dados da oportunidade!");
  1027. }
  1028. }
  1029. }
  1030. });
  1031. } else {
  1032. // $("#C5_REVISA").val("");
  1033. }
  1034. dialog.modal('hide');
  1035. }
  1036. /**
  1037. Atualiza o valor do frete
  1038. **/
  1039. function atuVlrFrete(){
  1040. var cUFEnt = $("#C5_UFENT").val().substr(0,2)
  1041. var cMunEnt = $("#C5_UFENT").val().substr(2,5)
  1042. if(cUFEnt != ""){
  1043. $.ajax({
  1044. url: "U_GetPerFrt.apw?PR=<%=cLCodLogin%>",
  1045. data: 'uf='+cUFEnt+'&mun='+cMunEnt,
  1046. type: "POST",
  1047. async: false,
  1048. success:
  1049. function(frete) {
  1050. if (frete.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  1051. $("html").html(frete);
  1052. return;
  1053. } else {
  1054. //Atualiza o frete
  1055. $("#C5_PERCFRT").removeAttr("disabled");
  1056. $("#C5_PERCFRT").val(frete);
  1057. }
  1058. }
  1059. });
  1060. }
  1061. }
  1062. /**
  1063. Valida o estudo
  1064. **/
  1065. // function vldEstudo(){
  1066. // var cEstudo = $("#CJ_LUMINOT").val();
  1067. // if(cEstudo == "1"){
  1068. // $("#C5_REGLUMI").removeAttr('disabled');
  1069. // } else {
  1070. // $("#C5_REGLUMI").val("");
  1071. // $("#select2-C5_REGLUMI-container").html($("#C5_REGLUMI option[value='']").html());
  1072. // $("#C5_REGLUMI").attr("disabled","");
  1073. // }
  1074. // }
  1075. /**
  1076. Valida a prospecção
  1077. **/
  1078. function vldProspec(){
  1079. var cProspec = $("#C5_PROPECC").val();
  1080. if(cProspec == "S"){
  1081. $("#C5_PROSCOD").removeAttr('disabled');
  1082. } else {
  1083. $("#C5_PROSCOD").val("");
  1084. $("#select2-C5_PROSCOD-container").html($("#C5_PROSCOD option[value='']").html());
  1085. $("#C5_PROSCOD").attr("disabled","");
  1086. }
  1087. }
  1088. /**
  1089. Valida o campo prospectado por
  1090. **/
  1091. function vldProsPor(){
  1092. var cProspec = $("#C5_PROPECC").val();
  1093. var cProsPor = $("#C5_PROSCOD").val();
  1094. if(cProspec == "S" && cProsPor == ""){
  1095. bootbox.alert("Informe o campo Prospectado Por!")
  1096. }
  1097. if (cProspec == "N"){
  1098. $("#C5_PROSCOD").val("");
  1099. $("#select2-C5_PROSCOD-container").html($("#C5_PROSCOD option[value='']").html());
  1100. $("#C5_PROSCOD").attr("disabled","");
  1101. }
  1102. }
  1103. /**
  1104. Valida a condição de pagamento selecionada
  1105. **/
  1106. function vldCond(){
  1107. var valDesc = 0;
  1108. $.ajax({
  1109. url: "U_VldCondPg.apw?PR=<%=cLCodLogin%>",
  1110. data: 'condPgto='+$("#C5_CONDPAG").val(),
  1111. type: "POST",
  1112. async: false,
  1113. success:
  1114. function(retorno) {
  1115. valDesc = parseFloat(retorno);
  1116. //Atualiza a variável
  1117. $("#DESCCOND").val(valDesc);
  1118. if (valDesc > 0) {
  1119. bootbox.alert("Condição de pagamento com desconto. Ao salvar o Pedido será aplicado o desconto de "+mascaraValor(valDesc.toFixed(2))+"%.");
  1120. } else {
  1121. $("#DESCCOND").val("0");
  1122. }
  1123. //Atualiza o valor do produto quando altera a condição de pagamento
  1124. if ($('#iC6_PRCVEN01').val()!=$('#C6_PRCVEN01').val() || $("#DESCCOND").val()=="0"){
  1125. AtuValProd();
  1126. }
  1127. }
  1128. });
  1129. }
  1130. /**
  1131. Busca dados do cliente a partir do código ou nome
  1132. **/
  1133. function buscarClientes(cCliBusca,callback){
  1134. if (cCliBusca != ""){
  1135. $.ajax({
  1136. url: "U_GetLikeCli.apw?PR=<%=cLCodLogin%>",
  1137. data: 'digit=' + cCliBusca,
  1138. method: "POST",
  1139. async: false,
  1140. success: function( clientes ) {
  1141. if (clientes.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ||clientes.toUpperCase().indexOf("EXPIRES") != -1) {
  1142. $("html").html(clientes);
  1143. callback([]); // Retorna uma lista vazia em caso de erro
  1144. }
  1145. if (clientes == "") {
  1146. $("#C5_CLIENTE").empty();
  1147. bootbox.alert('Não foram encontrados clientes para o termo pesquisado!');
  1148. callback([]); // Retorna uma lista vazia em caso de erro
  1149. } else {
  1150. $("#C5_CLIENTE").empty(); // Limpa o conteúdo existente
  1151. var selectpicker = $("<select>", {
  1152. class: "selectpicker",
  1153. title: "Selecione um cliente"
  1154. });
  1155. selectpicker.append($.parseHTML(clientes));
  1156. // Adiciona os valores dos elementos <option> listaClientes
  1157. var listaClientes = selectpicker.find('option').map(function () {
  1158. return $(this).text();//Pegar o texto completo
  1159. }).get();
  1160. $("#C5_CLIENTE").append(selectpicker);
  1161. callback(listaClientes); // Retorna a lista de clientes encontrados
  1162. }
  1163. }
  1164. });
  1165. } else {
  1166. bootbox.alert("Informe o cliente para busca!");
  1167. }
  1168. }
  1169. /**
  1170. Monta a tela para selecionar o produto
  1171. **/
  1172. function getProduto(btPesquisa){
  1173. var objProd = btPesquisa.closest("td").find("[autocomplete=off]");
  1174. var cProdBusca = $("#"+objProd.attr("name")).val().toUpperCase();
  1175. //var nItem = btPesquisa[0].id.substr(8,2);
  1176. var nItem = objProd.attr("name").substr(10);
  1177. $("#PROXIMO").val(nItem);
  1178. // Usando a função buscarProdutos com um callback
  1179. buscarProdutos(cProdBusca, nItem, function (produtosEncontrados) {
  1180. if (produtosEncontrados.length >= 1) {
  1181. var selectOptions = '<select id="produtoSelecionado">';
  1182. //var selectOptions = '<select data-plugin-selectTwo class="form-control populate placeholder" data-plugin-options="{ "placeholder": "Selecione...", "allowClear": false }" id="produtoSelecionado">';
  1183. var indiceHifen;
  1184. var selOptions = '';
  1185. produtosEncontrados.forEach(function (produto) {
  1186. selectOptions += "<option value='" + produto + "'>" + produto + "</option>";
  1187. //selOptions+= "{text: '"+produto+"',value: '"+produto+"'},";
  1188. });
  1189. selectOptions += "</select>";
  1190. bootbox.dialog({
  1191. title: 'Produtos',
  1192. message: "<p>Selecione o produto desejado:</p>" + selectOptions,
  1193. backdrop: false,
  1194. size: 'large',
  1195. buttons: {
  1196. confirm: {
  1197. label: 'Confirmar',
  1198. className: 'btn-primary',
  1199. callback: function () {
  1200. var produtoSelecionado = $("#produtoSelecionado").val();
  1201. // Atualiza o campo original com o produto escolhido
  1202. $("#C6_PRODUTO" + nItem).val(produtoSelecionado);
  1203. produtoSelecionado = formataProd(produtoSelecionado);
  1204. gatProduto(objProd,produtoSelecionado);
  1205. }
  1206. },
  1207. cancel: {
  1208. label: 'Cancelar',
  1209. className: 'btn-default',
  1210. callback: function () {
  1211. }
  1212. }
  1213. }
  1214. });
  1215. }
  1216. });
  1217. }
  1218. /**
  1219. Busca dados do produto a partir do código ou descrição
  1220. **/
  1221. function buscarProdutos(cProdBusca,item,callback){
  1222. var cliente = formataCli($("#C5_CLIENTE").val());
  1223. var tabpreco = $("#C5_TABELA").val();
  1224. //var item = $("#PROXIMO").val();
  1225. if (cProdBusca != ""){
  1226. if(cliente == ""){
  1227. bootbox.alert("Selecione o cliente para continuar!");
  1228. return false;
  1229. }
  1230. $.ajax({
  1231. url: "U_GetLikePro.apw?PR=<%=cLCodLogin%>",
  1232. data: 'cliente=' + cliente + '&tabela=' + tabpreco + '&digit=' + cProdBusca,
  1233. method: "POST",
  1234. async: false,
  1235. success: function( produtos ) {
  1236. if (produtos.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ||produtos.toUpperCase().indexOf("EXPIRES") != -1) {
  1237. $("html").html(produtos);
  1238. callback([]); // Retorna uma lista vazia em caso de erro
  1239. }
  1240. if (produtos == "") {
  1241. LimpaLinha(item);
  1242. bootbox.alert('Não foram encontrados produtos para o termo pesquisado!');
  1243. callback([]); // Retorna uma lista vazia em caso de erro
  1244. } else {
  1245. $("#C6_PRODUTO" + item).empty(); // Limpa o conteudo existente
  1246. /*
  1247. // Preenche o select dos produtos
  1248. $("#C6_PRODUTO" + item).empty(); // Limpa o conteudo existente
  1249. $("#C6_PRODUTO"+item).append($.parseHTML(produtos));
  1250. $('.selectpicker').selectpicker('render');
  1251. $('.selectpicker').selectpicker('refresh');
  1252. optProd = produtos;
  1253. */
  1254. var selectpicker = $("<select>", {
  1255. class: "selectpicker",
  1256. title: "Selecione um produto"
  1257. });
  1258. selectpicker.append($.parseHTML(produtos));
  1259. // Adiciona os valores dos elementos <option> listaProdutos
  1260. var listaProdutos = selectpicker.find('option').map(function () {
  1261. //return $(this).val();
  1262. ////Luiz SMS - 04/01/2024
  1263. return $(this).text();//Pegar o texto completo
  1264. }).get();
  1265. $("#C6_PRODUTO" + item).append(selectpicker);
  1266. callback(listaProdutos); // Retorna a lista de produtos encontrados
  1267. }
  1268. }
  1269. });
  1270. } else {
  1271. bootbox.alert("Informe o produto para busca!");
  1272. }
  1273. }
  1274. /**
  1275. Converte o texto para maiusculo
  1276. **/
  1277. function Maiuscula(cItemAtu){
  1278. var cCodBar = $("#"+cItemAtu.attr("id")).val().toUpperCase();
  1279. $(cItemAtu).val(cCodBar);
  1280. }
  1281. /**
  1282. Gatilho acionado ao selecionar o produto para preencher os valores
  1283. **/
  1284. function gatProduto(objInput,produtoSelecionado) {
  1285. var nItens = parseFloat($("#PROXIMO").val());
  1286. var lProdOK = true;
  1287. var nItem = objInput.attr("name").substr(10);
  1288. var dialogProd = bootbox.dialog({
  1289. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Buscando dados do produto... Aguarde...</p>',
  1290. closeButton: false
  1291. });
  1292. //valida a digitação duplicada de itens
  1293. for (i = 1; i<=nItens; i++) {
  1294. cItem = String(i);
  1295. if (parseInt(i) < 10 ){cItem = "0"+String(i)};
  1296. cItmOrc = $("#C6_ITEM"+cItem).val();
  1297. if(cItmOrc != "x" && nItem != cItem ) {
  1298. if ($('#C6_PRODUTO'+cItem).val() == objInput.val()){
  1299. lProdOK = false;
  1300. $('#C6_PRODUTO'+nItem).val("");
  1301. $("#select2-C6_PRODUTO"+cItem+"-container").html("Selecione...");
  1302. }
  1303. }
  1304. }
  1305. if (!lProdOK ) {
  1306. bootbox.alert("Este item já foi informado no Pedido!");
  1307. dialogProd.modal('hide');
  1308. }
  1309. //Fim da validação de itens duplicados
  1310. if ( ! objInput.is('[readonly]') && $.trim(objInput.val()) != "" && lProdOK ) {
  1311. jQuery.ajax({
  1312. type: "POST",
  1313. url: "U_pGATPROD.APW?PR=<%=cLCodLogin%>",
  1314. data: 'produto='+encodeURIComponent(produtoSelecionado)+'&tabela='+$("#C5_TABELA").val()+'&frete='+$("#C5_PERCFRT").val()+'&comisRT='+$("#C5_COMISTR").val()+'&lumoper='+$("#C5_TIPOLUM").val()+'&vend2='+$("#C5_VEND2").val()+'&vend3='+$("#C5_VEND3").val()+'&vend4='+$("#C5_VEND4").val(),
  1315. error: function (jqXHR, textStatus, error){
  1316. dialogProd.modal('hide');
  1317. bootbox.alert("Falha ao recuperar informações!");
  1318. console.log(error);
  1319. },
  1320. success: function( data ) {
  1321. var aVlr;
  1322. var cMsgErro;
  1323. var nItem = objInput.attr("name").substr(10);
  1324. var przEmb = parseInt($("#C5_PRZEMB").val());
  1325. dialogProd.modal('hide');
  1326. if (data.substr(0, 2) == "OK") {
  1327. aVlr = data.substr(3).split('|#|');
  1328. if (aVlr[18] != "" && aVlr[18] != "::") {
  1329. var dialog = bootbox.dialog({
  1330. title: 'Mensagem do Produto',
  1331. message: "<p>"+aVlr[19]+"</p>",
  1332. backdrop: true,
  1333. buttons: {
  1334. ok: {
  1335. label: "OK"
  1336. }
  1337. }
  1338. });
  1339. }
  1340. //Validação do produto chamada no VldPortalSMS
  1341. if(aVlr[17] == "1"){
  1342. //Limpa a quantidade caso tenha alterado o produto
  1343. $.trim($("input[name='C6_QTDVEN"+nItem+"']").val(""));
  1344. //Validação do prazo de embarque
  1345. if (aVlr[19] != ""){
  1346. bootbox.alert("Este item não tem estrutura de produção.<br>O prazo de entrega será acrescido de "+aVlr[19]+" dia(s).");
  1347. przEmb = przEmb+parseInt(aVlr[19]);
  1348. }
  1349. $("input[id='C6_PRZEMB"+nItem+"']").val(String(przEmb));
  1350. $.trim($("input[name='C6_PRCVEN"+nItem+"']").val(aVlr[1]));
  1351. $.trim($("input[name='iC6_PRCVEN"+nItem+"']").val(aVlr[1]));
  1352. //Verifica tipo e grupo do produto
  1353. if(aVlr[20]=="PS" && aVlr[13]=="SERV"){
  1354. bootbox.confirm({
  1355. title: "Custo e Preço de Venda do Serviço",
  1356. message: "Deseja informar o Custo e o Preço de Venda do serviço?",
  1357. buttons: {
  1358. cancel: {
  1359. label: 'Não'
  1360. },
  1361. confirm: {
  1362. label: 'Sim'
  1363. }
  1364. },
  1365. callback: function (result) {
  1366. if (result){
  1367. //Chama tela para informar os dois campos
  1368. informaCusto(nItem);
  1369. }
  1370. }
  1371. });
  1372. }
  1373. nVlrVenda = $('#C6_PRCVEN'+nItem).maskMoney('unmasked')[0];
  1374. nPerFrete = $('#C5_PERCFRT').maskMoney('unmasked')[0];
  1375. nRT = $('#C5_COMISTR').maskMoney('unmasked')[0];
  1376. //soma percentual de frete e RT
  1377. if(nVlrVenda > 0 ){
  1378. if(nPerFrete > 0 ){
  1379. nVlrVenda = nVlrVenda + ((nVlrVenda * nPerFrete)/100);
  1380. }
  1381. if(nRT > 0 ){
  1382. nVlrVenda = nVlrVenda + ((nVlrVenda * nRT)/100);
  1383. }
  1384. }
  1385. $("input[name='C6_UM"+nItem+"']").val(aVlr[0]);
  1386. $.trim($("input[name='C6_PRCVEN"+nItem+"']").val(nVlrVenda)); //aVlr[1]
  1387. $.trim($("input[name='iC6_PRCVEN"+nItem+"']").val(nVlrVenda)); //aVlr[1]
  1388. $.trim($("input[name='C6_XVALICM"+nItem+"']").val(aVlr[2]));
  1389. $.trim($("input[name='C6_XVALIPI"+nItem+"']").val(aVlr[3]));
  1390. $.trim($("input[name='C6_XICMST"+nItem+"']").val(aVlr[4]));
  1391. $.trim($("input[name='C6_LOCAL"+nItem+"']").val(aVlr[15]));
  1392. //Input hidden
  1393. $("input[id='ALIQ_IPI"+nItem+"']").val(aVlr[5]);
  1394. $("input[id='ALIQ_ICMS"+nItem+"']").val(aVlr[6]);
  1395. $("input[id='ALIQ_ST"+nItem+"']").val(aVlr[12]);
  1396. $("input[id='BASE_IPI"+nItem+"']").val(aVlr[11]);
  1397. $("input[id='BASE_ICMS"+nItem+"']").val(aVlr[9]);
  1398. $("input[id='BASE_ST"+nItem+"']").val(aVlr[10]);
  1399. $("input[id='VAL_ICMS"+nItem+"']").val(aVlr[2]);
  1400. $("input[id='VAL_ST"+nItem+"']").val(aVlr[4]);
  1401. $("input[id='VAL_IPI"+nItem+"']").val(aVlr[3]);
  1402. $("input[id='QTD_EMB"+nItem+"']").val(aVlr[7]);
  1403. $("input[id='C6_TES"+nItem+"']").val(aVlr[8]);
  1404. $("input[id='GRUPO"+nItem+"']").val(aVlr[13]);
  1405. $("input[id='QTDMIN"+nItem+"']").val(aVlr[14]);
  1406. $("input[id='EST_DISP"+nItem+"']").val(aVlr[16]);
  1407. $("input[id='VENCIMENTO"+nItem+"']").val(aVlr[15]);
  1408. $("input[id='C6_PRUNIT"+nItem+"']").val(nVlrVenda);
  1409. $("input[id='C6_OPER"+nItem+"']").val(aVlr[21]);
  1410. $("input[id='C6_POSIPI"+nItem+"']").val(aVlr[22]);
  1411. $("input[id='C6_CF"+nItem+"']").val('6101');
  1412. $("input[id='C6_ENTREG"+nItem+"']").val($('#C5_DATENTR').val());
  1413. //Salva o valor do imposto pro preço cheio
  1414. if($("#IMP_PRCTAB"+nItem).val() == 0){
  1415. nPrcImp = parseFloat(aVlr[3].replace(",","."))+parseFloat(aVlr[4].replace(",","."));
  1416. $("#IMP_PRCTAB"+nItem).val(nPrcImp);
  1417. }
  1418. $("input[id='C6_COMIS2"+nItem+"']").val(aVlr[23]);
  1419. $("input[id='C6_COMIS3"+nItem+"']").val(aVlr[24]);
  1420. $("input[id='C6_COMIS4"+nItem+"']").val(aVlr[25]);
  1421. $("input[id='B1_COMIS"+nItem+"']").val(aVlr[26]);
  1422. //Limpa os inputs, caso tenha trocado o produto
  1423. $("input[name='C6_QTDVEN"+nItem+"']").removeAttr('disabled');
  1424. $("input[name='C6_ENTREG"+nItem+"']").removeAttr('disabled');
  1425. $("input[name='C6_PRCVEN"+nItem+"']").removeAttr('disabled');
  1426. $("input[name='C6_ENTREG"+nItem+"']").removeAttr('disabled');
  1427. // $("input[name='C6_OPER"+nItem+"']").removeAttr('disabled');
  1428. // $("input[name='C6_TES"+nItem+"']").removeAttr('disabled');
  1429. // $("input[name='C6_CF"+nItem+"']").removeAttr('disabled');
  1430. $("input[name='C6_PEDCLI"+nItem+"']").removeAttr('disabled');
  1431. $("input[name='C6_IPEDCLI"+nItem+"']").removeAttr('disabled');
  1432. $("input[name='C6_COMIS2"+nItem+"']").removeAttr('disabled');
  1433. $("input[name='C6_COMIS3"+nItem+"']").removeAttr('disabled');
  1434. $("input[name='C6_COMIS4"+nItem+"']").removeAttr('disabled');
  1435. $("input[name='C6_VALOR"+nItem+"']").val("0,00");
  1436. } else {
  1437. LimpaLinha(nItem);
  1438. }
  1439. } else {
  1440. if (data.substr(0, 4) == "ERRO") {
  1441. cMsgErro = data.substr(5);
  1442. bootbox.alert(cMsgErro);
  1443. LimpaLinha(nItem);
  1444. } else {
  1445. cMsgErro = "Houve falha ao localizar os dados do produto. Tente novamente!";
  1446. bootbox.alert(cMsgErro);
  1447. LimpaLinha(nItem);
  1448. // Quando ocorre erro no protheus
  1449. console.log(data);
  1450. }
  1451. }
  1452. }
  1453. });
  1454. } else if ($.trim(objInput.val()) == "" ) {
  1455. LimpaLinha(nItem);
  1456. }
  1457. return false;
  1458. }
  1459. /**
  1460. Funcao para informar o custo do serviço
  1461. **/
  1462. function informaCusto(cItemAtu) {
  1463. $("#itemAtu").val(cItemAtu);
  1464. $("#dialogCusto").modal('show');
  1465. }
  1466. /**
  1467. Funcao que grava o custo do serviço
  1468. **/
  1469. function gravaCusto(itemAtu,prcVenda,custo){
  1470. var qtd = parseFloat($("#C6_QTDVEN"+itemAtu).val().replace('.',"").replace(",","."));
  1471. var totalCusto = 0;
  1472. custoUnt = $("#CUSTO").maskMoney('unmasked')[0];
  1473. if(qtd == 0){qtd = 1};
  1474. totalCusto = custoUnt * qtd;
  1475. $("#C6_CUSTO"+itemAtu).val(mascaraValor(totalCusto.toFixed(2)));
  1476. $("#C6_PRCVEN"+itemAtu).val(prcVenda);
  1477. $("#iC6_PRCVEN"+itemAtu).val(prcVenda);
  1478. $("#dialogCusto").modal('hide');
  1479. }
  1480. /**
  1481. Funcao de calculo do total do item
  1482. **/
  1483. function TotalItem(cItemAtu) {
  1484. var nQuant;
  1485. var nVlrUnit;
  1486. var nVlrTabela;
  1487. var nVlrCusto;
  1488. var nTotalCusto;
  1489. var nTotalUnit;
  1490. var nICMS;
  1491. var nICMSST;
  1492. var nIPI;
  1493. var nPerDesc = 0;
  1494. var nValFrete;
  1495. var nVlrTotal;
  1496. var nBaseIPI;
  1497. var nBaseICMS;
  1498. var nBaseST;
  1499. var cFaixaDesc;
  1500. var nPerCom = 0;
  1501. var nValCom = 0;
  1502. var nValDesc = 0;
  1503. cCodProd = formataProd($("#C6_PRODUTO"+cItemAtu).val());
  1504. nQuant = parseFloat($("#C6_QTDVEN"+cItemAtu).val().replace('.',"").replace(",","."));
  1505. nVlrTabela = $('#iC6_PRCVEN'+cItemAtu).maskMoney('unmasked')[0];
  1506. nVlrCusto = $('#C6_CUSTO'+cItemAtu).maskMoney('unmasked')[0];
  1507. //nVlrTabela = $('#C6_PRCVEN'+cItemAtu).maskMoney('unmasked')[0];
  1508. //nVlrUnit = $('#iC6_PRCVEN'+cItemAtu).maskMoney('unmasked')[0];
  1509. nValFrete = $("#C5_FRETE").maskMoney('unmasked')[0];
  1510. if ($('#C6_DESCONT'+cItemAtu).maskMoney('unmasked')[0] != 0){
  1511. nPerDesc = $("#C6_DESCONT"+cItemAtu).maskMoney('unmasked')[0];
  1512. }
  1513. nVlrUnit = nVlrTabela - (nVlrTabela*(nPerDesc/100));
  1514. nVlrTotal = nVlrUnit*nQuant;
  1515. nTotalUnit = nVlrTotal;
  1516. nValDesc = nVlrTabela*(nPerDesc/100);
  1517. nTotalCusto = nVlrCusto*nQuant;
  1518. //Tratamento para os impostos
  1519. nICMS = $('#C6_XVALICM'+cItemAtu).maskMoney('unmasked')[0];
  1520. nICMSST = $('#C6_XICMST'+cItemAtu).maskMoney('unmasked')[0];
  1521. nIPI = $("#C6_XVALIPI"+cItemAtu).maskMoney('unmasked')[0];
  1522. //Aliquotas
  1523. nAliqIPI = parseFloat($("#ALIQ_IPI"+cItemAtu).val());
  1524. nAliqICMS = parseFloat($("#ALIQ_ICMS"+cItemAtu).val());
  1525. nAliqST = parseFloat($("#ALIQ_ST"+cItemAtu).val());
  1526. //Valores Base
  1527. nBaseIPI = parseFloat($("#BASE_IPI"+cItemAtu).val());
  1528. nBaseICMS = parseFloat($("#BASE_ICMS"+cItemAtu).val());
  1529. nBaseST = parseFloat($("#BASE_ST"+cItemAtu).val());
  1530. //Valor do imposto
  1531. nIPI = nBaseIPI * nQuant * (nAliqIPI /100)
  1532. nICMS = nBaseICMS * nQuant * (nAliqICMS /100)
  1533. nICMSST = nQuant * parseFloat($("#VAL_ST"+cItemAtu).val().replace(",","."));
  1534. //nIPI = nVlrTotal*(nAliqIPI /100)
  1535. //nICMS = nVlrTotal*(nAliqICMS /100)
  1536. //nIPI = nQuant * parseFloat($("#VAL_IPI"+cItemAtu).val().replace(",","."));
  1537. //nICMS = nQuant * parseFloat($("#VAL_ICMS"+cItemAtu).val().replace(",","."));
  1538. //nICMSST = nQuant * parseFloat($("#VAL_ST"+cItemAtu).val().replace(",","."));
  1539. nVlrTotal = nVlrTotal+nIPI+nICMSST;
  1540. nTotalUnit = nVlrTotal / nQuant;
  1541. //Atualiza o campo do total
  1542. $.trim($("#C6_XVALICM"+cItemAtu).val(mascaraValor(nICMS.toFixed(2))));
  1543. $.trim($("#C6_XVALIPI"+cItemAtu).val(mascaraValor(nIPI.toFixed(2))));
  1544. $.trim($("#C6_XICMST"+cItemAtu).val(mascaraValor(nICMSST.toFixed(2))));
  1545. $.trim($("#C6_PRCVEN"+cItemAtu).val(mascaraValor(nVlrUnit.toFixed(2))));
  1546. $.trim($("#C6_CUSTO"+cItemAtu).val(mascaraValor(nTotalCusto.toFixed(2))));
  1547. $.trim($("#C6_VALOR"+cItemAtu).val(mascaraValor(nVlrTotal.toFixed(2))));
  1548. $.trim($("#C6_XPRCIMP"+cItemAtu).val(mascaraValor(nTotalUnit.toFixed(2))));
  1549. //Atualiza o total geral
  1550. TotalGeral();
  1551. }
  1552. /**
  1553. Total Geral
  1554. **/
  1555. function TotalGeral() {
  1556. var nItens = parseFloat($("#PROXIMO").val());
  1557. var i;
  1558. var nVlrTabela = 0;
  1559. var nVlrUnit = 0;
  1560. var nICMS = 0;
  1561. var nICMSST = 0;
  1562. var nIPI = 0;
  1563. var nImpostos = 0;
  1564. var nValFrete = 0;
  1565. var nTotal = 0;
  1566. var nAcresc = 0;
  1567. var nDescCond = 0;
  1568. var nQuant = 0;
  1569. var nValCom = 0;
  1570. var cCodProd;
  1571. var cItmOrc;
  1572. var nTotQuant = 0.00;
  1573. var nPerDesc = 0;
  1574. var nValDesc = 0;
  1575. var nVlrSDesc = 0
  1576. for (i = 1; i<=nItens; i++) {
  1577. cItem = String(i);
  1578. if (parseInt(i) < 10 ){cItem = "0"+String(i)};
  1579. cCodProd = formataProd($("#C6_PRODUTO"+cItem).val());
  1580. cItmOrc = $("#C6_ITEM"+cItem).val();
  1581. if(cItmOrc != "x") {
  1582. nQuant = parseFloat($("#C6_QTDVEN"+cItem).val().replace('.',"").replace(",","."));
  1583. nTotQuant += nQuant;
  1584. nVlrUnit += nQuant * $('#iC6_PRCVEN'+cItem).maskMoney('unmasked')[0];
  1585. nICMS += $('#C6_XVALICM'+cItem).maskMoney('unmasked')[0];
  1586. nICMSST += $('#C6_XICMST'+cItem).maskMoney('unmasked')[0];
  1587. nIPI += $("#C6_XVALIPI"+cItem).maskMoney('unmasked')[0];
  1588. nValCom += $("#VAL_COM"+cItem).maskMoney('unmasked')[0];
  1589. nTotal += $('#C6_VALOR'+cItem).maskMoney('unmasked')[0];
  1590. if ($('#C6_DESCONT'+cItem).maskMoney('unmasked')[0] != 0){
  1591. nPerDesc = $("#C6_DESCONT"+cItem).maskMoney('unmasked')[0];
  1592. nValDesc += nVlrUnit*(nPerDesc/100);
  1593. }
  1594. }
  1595. }
  1596. nImpostos = nICMSST+nIPI; //nICMS
  1597. nValFrete = $("#C5_FRETE").maskMoney('unmasked')[0];
  1598. /*
  1599. //Verifica acrescimo da condição de pagamento
  1600. $.ajax({
  1601. url: "U_ValAcresc.apw?PR=<%=cLCodLogin%>",
  1602. data: 'condPgto='+$("#C5_CONDPAG").val()+'&valor='+nTotal,
  1603. type: "POST",
  1604. async: false,
  1605. success:
  1606. function(retorno) {
  1607. //nAcresc = parseFloat(retorno);
  1608. nAcresc = parseFloat(nTotal*(retorno/100))
  1609. }
  1610. });
  1611. */
  1612. //nDescCond = parseFloat((nTotal-nTotalProm)*($("#DESCCOND").val()/100)); //desconto da condição de pagamento
  1613. nDescCond = parseFloat(nTotal*($("#DESCCOND").val()/100)); //desconto da condição de pagamento
  1614. nTotal = (nTotal+nValFrete+nAcresc)-nDescCond;
  1615. nPrcImp = parseFloat($("#IMP_PRCTAB"+cItem).val().replace(",","."));
  1616. nVlrSDesc = nVlrUnit+nPrcImp;
  1617. //nVlrSDesc = nVlrUnit+nImpostos;
  1618. nTotalIt = (nVlrSDesc-nValDesc);
  1619. //Atualiza os totais
  1620. $("#TOTAL_ITENS_NODESC").val($.trim(mascaraValor(nVlrUnit.toFixed(2))));
  1621. $("#TOTAL_NODESC_IMP").val($.trim(mascaraValor((nVlrSDesc).toFixed(2))));
  1622. $("#TOTAL_QITENS").val($.trim(mascaraValor(nTotQuant.toFixed(2))));
  1623. $("#TOTAL_ITENS").val($.trim(mascaraValor((nTotalIt).toFixed(2))));
  1624. $("#TOTAL_IMP").val($.trim(mascaraValor(nImpostos.toFixed(2))));
  1625. $("#TOTAL_FRETE").val($("#C5_FRETE").val());
  1626. $("#TOTAL_ACRESC").val($.trim(mascaraValor(nDescCond.toFixed(2))));
  1627. $("#TOTAL_ORC").val($.trim(mascaraValor(nTotal.toFixed(2))));
  1628. $("#TOTAL_COM").val($.trim(mascaraValor(nValCom.toFixed(2))));
  1629. }
  1630. /**
  1631. Atualiza o valor do produto ao trocar a condição de pagamento
  1632. **/
  1633. function AtuValProd(){
  1634. var nItens = parseFloat($("#PROXIMO").val());
  1635. var i;
  1636. var nvalorcheio = 0;
  1637. for (i = 1; i<=nItens; i++) {
  1638. cItem = String(i);
  1639. if (parseInt(i) < 10 ){cItem = "0"+String(i)};
  1640. cItmOrc = $("#C6_ITEM"+cItem).val();
  1641. if(cItmOrc != "x") {
  1642. nvalorcheio = $('#C6_PRCVEN'+cItem).val();
  1643. $('#iC6_PRCVEN'+cItem).val(nvalorcheio);
  1644. TotalItem(cItem);
  1645. }
  1646. }
  1647. }
  1648. /**
  1649. Verifica se a quantidade é multiplo da embalagem
  1650. **/
  1651. function VldQtd(cItemAtu) {
  1652. var nQuant;
  1653. var nQtdEmb;
  1654. var nQtdMin;
  1655. var resto;
  1656. var cCodProd = formataProd($("#C6_PRODUTO"+cItemAtu).val());
  1657. var lRet = true;
  1658. //Valida a quantidade por embalagem
  1659. nQtdEmb = parseFloat($("#QTD_EMB"+cItemAtu).val());
  1660. nQtdMin = $("#QTDMIN"+cItemAtu).val();
  1661. nQuant = parseFloat($("#C6_QTDVEN"+cItemAtu).val().replace('.',"").replace(",","."));
  1662. if (nQuant > 0){
  1663. //Valida a quantidade da embalagem
  1664. if (nQtdEmb > 0){
  1665. if (nQuant < (nQtdEmb)){
  1666. bootbox.alert("A quantidade deve ser múltiplo de "+nQtdEmb.toString()+".");
  1667. $("#C6_QTDVEN"+cItemAtu).val("");
  1668. lRet = false;
  1669. return false;
  1670. } else {
  1671. resto = nQuant % nQtdEmb;
  1672. if (resto != 0 ){
  1673. bootbox.alert("A quantidade deve ser múltiplo de "+nQtdEmb.toString()+".");
  1674. $("#C6_QTDVEN"+cItemAtu).val("");
  1675. lRet = false;
  1676. return false;
  1677. }
  1678. }
  1679. }
  1680. /*
  1681. var dialogProd = bootbox.dialog({
  1682. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Buscando dados do produto... Aguarde...</p>',
  1683. closeButton: false
  1684. });
  1685. //Atualiza o preço de acordo com a quantidade
  1686. // Encontra a posição do primeiro h?fen na string
  1687. indiceHifen = cCodProd.indexOf("--");
  1688. //Pega apenas o codigo do produto
  1689. cCodProd = cCodProd.substring(0, indiceHifen);
  1690. //Remove espaços vazios
  1691. cCodProd = cCodProd.trim();
  1692. jQuery.ajax({
  1693. type: "POST",
  1694. url: "U_GATPROD.APW?PR=<%=cLCodLogin%>",
  1695. data: 'produto='+encodeURIComponent(cCodProd)+'&tabela='+$("#C5_TABELA").val(),
  1696. error: function (jqXHR, textStatus, error){
  1697. dialogProd.modal('hide');
  1698. bootbox.alert("Falha ao recuperar informações!");
  1699. console.log(error);
  1700. },
  1701. success: function( data ) {
  1702. var aVlr;
  1703. var cMsgErro;
  1704. dialogProd.modal('hide');
  1705. if (data.substr(0, 2) == "OK") {
  1706. aVlr = data.substr(3).split('|#|');
  1707. $("input[name='C6_UM"+cItemAtu+"']").val(aVlr[0]);
  1708. $.trim($("input[name='C6_PRCVEN"+cItemAtu+"']").val(aVlr[1]));
  1709. $.trim($("input[name='iC6_PRCVEN"+cItemAtu+"']").val(aVlr[1]));
  1710. $.trim($("input[name='C6_XVALICM"+cItemAtu+"']").val(aVlr[2]));
  1711. $.trim($("input[name='C6_XVALIPI"+cItemAtu+"']").val(aVlr[3]));
  1712. $.trim($("input[name='C6_XICMST"+cItemAtu+"']").val(aVlr[4]));
  1713. $.trim($("input[name='C6_LOCAL"+cItemAtu+"']").val(aVlr[15]));
  1714. //Input hidden
  1715. $("input[id='ALIQ_IPI"+cItemAtu+"']").val(aVlr[5]);
  1716. $("input[id='ALIQ_ICMS"+cItemAtu+"']").val(aVlr[6]);
  1717. $("input[id='ALIQ_ST"+cItemAtu+"']").val(aVlr[12]);
  1718. $("input[id='BASE_IPI"+cItemAtu+"']").val(aVlr[11]);
  1719. $("input[id='BASE_ICMS"+cItemAtu+"']").val(aVlr[9]);
  1720. $("input[id='BASE_ST"+cItemAtu+"']").val(aVlr[10]);
  1721. $("input[id='VAL_ICMS"+cItemAtu+"']").val(aVlr[2]);
  1722. $("input[id='VAL_ST"+cItemAtu+"']").val(aVlr[4]);
  1723. $("input[id='VAL_IPI"+cItemAtu+"']").val(aVlr[3]);
  1724. $("input[id='QTD_EMB"+cItemAtu+"']").val(aVlr[7]);
  1725. $("input[id='C6_TES"+cItemAtu+"']").val(aVlr[8]);
  1726. $("input[id='GRUPO"+cItemAtu+"']").val(aVlr[13]);
  1727. $("input[id='QTDMIN"+cItemAtu+"']").val(aVlr[14]);
  1728. } else {
  1729. if (data.substr(0, 4) == "ERRO") {
  1730. cMsgErro = data.substr(5);
  1731. bootbox.alert(cMsgErro);
  1732. LimpaLinha(cItemAtu);
  1733. } else {
  1734. cMsgErro = "Houve falha ao localizar os dados do produto. Tente novamente!";
  1735. bootbox.alert(cMsgErro);
  1736. LimpaLinha(cItemAtu);
  1737. // Quando ocorre erro no protheus
  1738. console.log(data);
  1739. }
  1740. }
  1741. }
  1742. });
  1743. */
  1744. } else {
  1745. bootbox.alert("Informe a quantidade!");
  1746. lRet = false;
  1747. return false;
  1748. }
  1749. if (lRet == true){
  1750. //Valida o estoque do produto
  1751. //vldEstoque(cItemAtu);
  1752. //Desbloqueia os campos
  1753. $("#C6_OBS"+cItemAtu).removeAttr('disabled');
  1754. $("#C6_PRZEMB"+cItemAtu).removeAttr('disabled');
  1755. $("#C6_DESCONT"+cItemAtu).removeAttr('disabled');
  1756. //cPrzEmb = $("#C5_PRZEMB").val();
  1757. //$("#C6_PRZEMB"+cItemAtu).val(cPrzEmb);
  1758. }
  1759. //Gatilho para total do item
  1760. TotalItem(cItemAtu);
  1761. }
  1762. /**
  1763. Verifica se existe estoque disponível
  1764. **/
  1765. function vldEstoque(cItem){
  1766. var produto = formataProd($("#C6_PRODUTO"+cItem).val());
  1767. var quantidade = parseFloat($("#C6_QTDVEN"+cItem).val().replace('.',","));
  1768. var qtd = $("#C6_QTDVEN"+cItem).val();
  1769. var lret = true;
  1770. var retVld = true;
  1771. var dialogTab = bootbox.dialog({
  1772. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Verificando estoque disponível... Aguarde...</p>',
  1773. closeButton: false
  1774. });
  1775. $.ajax({
  1776. url: "U_GetEstDisp.apw?PR=<%=cLCodLogin%>",
  1777. data: 'produto='+encodeURIComponent(produto)+'&quantidade='+qtd,
  1778. type: "POST",
  1779. async: false,
  1780. success:
  1781. function(retorno) {
  1782. if (retorno.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  1783. $("html").html(retorno);
  1784. return;
  1785. }
  1786. saldo = parseInt(retorno);
  1787. $("#EST_DISP"+cItem).val(saldo);
  1788. if ( saldo <= 0 || saldo < quantidade) {
  1789. if(retorno < 0){
  1790. retorno = 0
  1791. };
  1792. dialogTab.modal('hide');
  1793. bootbox.alert('Não há saldo disponível em estoque para a quantidade solicitada para o item '+produto+'! <br>O saldo atual é de '+retorno+'.');
  1794. if ($('#C5_XTPORC').val() == "1"){
  1795. $("#C6_QTDVEN"+cItem).val("");
  1796. lret = false;
  1797. retVld = false;
  1798. }
  1799. }
  1800. }
  1801. });
  1802. if (lret == true){
  1803. //Habilita os campos para edição
  1804. $("#C6_XPEDCLI"+cItem).removeAttr('disabled');
  1805. $("#C6_XITEMCL"+cItem).removeAttr('disabled');
  1806. $("#C6_DESCONT"+cItem).removeAttr('disabled');
  1807. }
  1808. dialogTab.modal('hide');
  1809. return retVld;
  1810. }
  1811. /**
  1812. Limpa os valores da linha
  1813. **/
  1814. function LimpaLinha(cItem) {
  1815. $("#C6_QTDVEN"+cItem).val("");
  1816. $("#C6_PRZEMB"+cItem).val("");
  1817. $("#iC6_PRCVEN"+cItem).val("");
  1818. $("#C6_PRCVEN"+cItem).val("");
  1819. $("#C6_CUSTO"+cItem).val("");
  1820. $("#IMP_PRCTAB"+cItem).val("");
  1821. $("#C6_XPRCIMP"+cItem).val("");
  1822. $("#C6_XVALIPI"+cItem).val("");
  1823. $("#C6_XVALICM"+cItem).val("");
  1824. $("#C6_XICMST"+cItem).val("");
  1825. $("#C6_VALOR"+cItem).val("");
  1826. $("#PER_COM"+cItem).val("");
  1827. $("#VAL_COM"+cItem).val("");
  1828. $("#C6_DESCONT"+cItem).val("");
  1829. TotalGeral();
  1830. }
  1831. /**
  1832. Verifica se o valor digitado é maior que o valor de tabela
  1833. **/
  1834. function VldValor(cItemAtu,cVldDesc) {
  1835. var nVlrTabela = $('#iC6_PRCVEN'+cItemAtu).maskMoney('unmasked')[0];
  1836. var nVlrUnit = $('#C6_PRCVEN'+cItemAtu).maskMoney('unmasked')[0];
  1837. var produto = $("#C6_PRODUTO"+cItemAtu).val();
  1838. var cQuant = $("#C6_QTDVEN"+cItemAtu).val();
  1839. var nValMin = 0;
  1840. var nDescont = 0;
  1841. var nDescMax = 0;
  1842. var aDesc;
  1843. var lOK = true;
  1844. var lMostra = false;
  1845. var dialogTab = bootbox.dialog({
  1846. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Verificando valores... Aguarde...</p>',
  1847. closeButton: false
  1848. });
  1849. if ($('#C6_DESCONT'+cItemAtu).maskMoney('unmasked')[0] != 0){
  1850. nDescont = $('#C6_DESCONT'+cItemAtu).maskMoney('unmasked')[0];
  1851. //Verifica desconto negativo
  1852. if (nDescont < 0) {
  1853. dialogTab.modal('hide');
  1854. bootbox.alert('O desconto não deve ser negativo!');
  1855. $('#C6_DESCONT'+cItemAtu).val("");
  1856. return false;
  1857. }
  1858. //Verifica validação do desconto
  1859. if (cVldDesc == 'S'){
  1860. produto = formataProd(produto);
  1861. $.ajax({
  1862. url: "U_VldDescto.apw?PR=<%=cLCodLogin%>",
  1863. data: 'produto='+encodeURIComponent(produto)+'&prcvenda='+nVlrUnit+'&quantidade='+cQuant,
  1864. type: "POST",
  1865. async: false,
  1866. error: function (jqXHR, textStatus, error){
  1867. dialogTab.modal('hide');
  1868. bootbox.alert("Falha ao atualizar o valor dos impostos!");
  1869. console.log(error);
  1870. lOK = false;
  1871. },
  1872. success:
  1873. function(cTipoDesc) {
  1874. if(cTipoDesc=='3'){
  1875. bootbox.alert('Produtos do tipo RE, iniciados com RELUMI, do grupo PAN ou acessórios de produtos do grupo PAN não permitem descontos.');
  1876. $('#C6_DESCONT'+cItemAtu).val("");
  1877. return false;
  1878. }
  1879. if(cTipoDesc=='2'){
  1880. msg = '<div class="row form-group">'
  1881. //Usuario
  1882. msg +=' <div class="row form-group">'
  1883. msg +=' <div class="col-lg-1"></div>'
  1884. msg +=' <div class="col-lg-11">'
  1885. msg +=' <label class="control-label">Usuário</label>'
  1886. msg +=' <div class="input-group">'
  1887. msg +=' <input id="userName" class="form-control text-left" value="">'
  1888. msg +=' </div>'
  1889. msg +=' </div>'
  1890. msg +=' </div>'
  1891. //Senha
  1892. msg +=' <div class="row form-group">'
  1893. msg +=' <div class="col-lg-1"></div>'
  1894. msg +=' <div class="col-lg-3">'
  1895. msg +=' <label class="control-label">Senha</label>'
  1896. msg +=' <div class="input-group">'
  1897. msg +=' <input id="userPsw" class="form-control text-left" type="password" value="">'
  1898. msg +=' </div>'
  1899. msg +=' </div>'
  1900. //% de Desconto
  1901. msg +=' <div class="row form-group">'
  1902. msg +=' <div class="col-lg-1"></div>'
  1903. msg +=' <div class="col-lg-3">'
  1904. msg +=' <label class="control-label">% de Desconto</label>'
  1905. msg +=' <div class="input-group">'
  1906. msg +=' <input id="percDesc" class="form-control text-right percentual" type="text" value="" maxlenght="7" placeholder="0,00%">'
  1907. msg +=' </div>'
  1908. msg +=' </div>'
  1909. msg +=' </div>'
  1910. msg +='</div>'
  1911. bootbox.confirm({
  1912. title: 'Senha para Desconto',
  1913. message: "<p>"+msg+"</p>",
  1914. backdrop: true,
  1915. buttons: {
  1916. cancel: {
  1917. label: 'Cancelar'
  1918. },
  1919. confirm: {
  1920. label: 'Confirmar'
  1921. }
  1922. },
  1923. callback: function (result) {
  1924. if (result){
  1925. usrInput = $("#userName").val();
  1926. pswInput = $("#userPsw").val();
  1927. percDesc = $("#percDesc").val();
  1928. //Valida a senha digitada
  1929. $.ajax({
  1930. url: "U_VldSenha.apw?PR=<%=cLCodLogin%>",
  1931. type: "POST",
  1932. data: 'user='+usrInput+'&senha='+pswInput,
  1933. async: false,
  1934. success:
  1935. function(retorno) {
  1936. if (retorno.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ||retorno.toLowerCase().indexOf("Expires") != -1){
  1937. bootbox.alert('Não foi possível realizar a operação pois a sessão foi fechada. Faça login novamente.');
  1938. }
  1939. if(retorno == "NOK"){
  1940. bootbox.alert("Usuário ou senha inválidos!")
  1941. $('#C6_DESCONT'+cItemAtu).val("");
  1942. return false;
  1943. } else {
  1944. $('#C5_DSDIRET').val(percDesc);
  1945. // $('#C6_NOMDIRE'+cItemAtu).val(usrInput);
  1946. }
  1947. }
  1948. });
  1949. } else {
  1950. $('#C6_DESCONT'+cItemAtu).val("");
  1951. return false;
  1952. }
  1953. }
  1954. });
  1955. }
  1956. }
  1957. });
  1958. }
  1959. }
  1960. //Valida o valor máximo --retirado Lucilene 11.08.20
  1961. //if ( lOK && nVlrUnit > nVlrTabela){
  1962. // dialogTab.modal('hide');
  1963. // bootbox.alert("O valor máximo permitido é o valor da tabela!");
  1964. // $("#iC6_PRCVEN"+cItemAtu).val($('#C6_PRCVEN'+cItemAtu).val());
  1965. // $("#iC6_PRCVEN"+cItemAtu).focus();
  1966. // lOK = false;
  1967. //}
  1968. //dialogTab.modal('hide');
  1969. //Atualiza o valor dos impostos
  1970. if (lOK && nDescont != 0){
  1971. var cCodProd = formataProd($("#C6_PRODUTO"+cItemAtu).val());
  1972. var cQuant = $("#C6_QTDVEN"+cItemAtu).val();
  1973. var cLumOper = $("#C5_OPERLUM").val();
  1974. //var dialogImp = bootbox.dialog({
  1975. // message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Atualizando os valores dos impostos... Aguarde...</p>',
  1976. // closeButton: false
  1977. // });
  1978. nVlrUnit = nVlrTabela - (nVlrTabela * (nDescont/100))
  1979. $.ajax({
  1980. url: "U_pGetImpostos.apw?PR=<%=cLCodLogin%>",
  1981. data: 'produto='+encodeURIComponent(cCodProd)+'&prcvenda='+nVlrUnit+'&quantidade='+cQuant+'&lumoper='+cLumOper,
  1982. type: "POST",
  1983. async: false,
  1984. error: function (jqXHR, textStatus, error){
  1985. dialogTab.modal('hide');
  1986. bootbox.alert("Falha ao atualizar o valor dos impostos!");
  1987. console.log(error);
  1988. lOK = false;
  1989. },
  1990. success:
  1991. function(data) {
  1992. dialogTab.modal('hide');
  1993. if (data.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  1994. $("html").html(data);
  1995. return;
  1996. }
  1997. if (data.substr(0, 2) == "OK") {
  1998. aVlr = data.substr(3).split('|#|');
  1999. $.trim($("input[name='C6_XVALICM"+cItemAtu+"']").val(aVlr[2]));
  2000. $.trim($("input[name='C6_XICMST"+cItemAtu+"']").val(aVlr[4]));
  2001. $.trim($("input[name='C6_XVALIPI"+cItemAtu+"']").val(aVlr[3]));
  2002. $.trim($("#C6_PRCVEN"+cItemAtu).val(mascaraValor(nVlrUnit.toFixed(2))));
  2003. //Input hidden
  2004. $("input[id='ALIQ_IPI"+cItemAtu+"']").val(aVlr[5]);
  2005. $("input[id='ALIQ_ICMS"+cItemAtu+"']").val(aVlr[6]);
  2006. $("input[id='ALIQ_ST"+cItemAtu+"']").val(aVlr[12]);
  2007. $("input[id='C6_TES"+cItemAtu+"']").val(aVlr[8]);
  2008. $("input[id='BASE_IPI"+cItemAtu+"']").val(aVlr[11]);
  2009. $("input[id='BASE_ICMS"+cItemAtu+"']").val(aVlr[9]);
  2010. $("input[id='BASE_ST"+cItemAtu+"']").val(aVlr[10]);
  2011. $("input[id='VAL_ICMS"+cItemAtu+"']").val(aVlr[2]);
  2012. $("input[id='VAL_ST"+cItemAtu+"']").val(aVlr[4]);
  2013. $("input[id='VAL_IPI"+cItemAtu+"']").val(aVlr[3]);
  2014. } else {
  2015. cMsgErro = "Houve falha ao atualizar os impostos. Tente novamente!";
  2016. bootbox.alert(cMsgErro);
  2017. LimpaLinha(cItemAtu);
  2018. lOK = false;
  2019. if (data.substr(0, 4) == "ERRO") {
  2020. cMsgErro = data.substr(5);
  2021. } else {
  2022. // Quando ocorre erro no protheus
  2023. console.log(data);
  2024. }
  2025. }
  2026. }
  2027. });
  2028. }
  2029. dialogTab.modal('hide');
  2030. //Gatilho para total do item
  2031. if(lOK){
  2032. TotalItem(cItemAtu);
  2033. }
  2034. }
  2035. /**
  2036. Função para anexar os documentos ao Pedido
  2037. **/
  2038. function OrcGetAnex() {
  2039. $.ajax({
  2040. url: "U_OrcGetAn.apw?PR=<%=cLCodLogin%>",
  2041. type: "POST",
  2042. data: "fornece="+$("#fornece").val()+"&loja="+$("#loja").val(),
  2043. cache: false,
  2044. success: function(html){
  2045. $("#InfAnexos").html(html);
  2046. new PNotify({
  2047. title: 'Anexar arquivo',
  2048. text: 'Anexado com sucesso',
  2049. type: 'success',
  2050. icon: 'fa fa-file-o',
  2051. cornerclass: 'ui-pnotify-sharp'
  2052. });
  2053. $("#arquivo").remove();
  2054. }
  2055. });
  2056. }
  2057. /**
  2058. Funcao de validação do tipo de frete
  2059. **/
  2060. function VldFrete() {
  2061. var cFrete;
  2062. var tabpreco = $("#C5_TABELA").val();
  2063. cFrete = $("#C5_TPFRETE").val();
  2064. if (cFrete == 'S'||cFrete == 'T'||cFrete == 'F'){
  2065. $("#C5_FRETE").removeAttr("required");
  2066. $("#C5_FRETE").removeAttr("aria-required");
  2067. $("#C5_FRETE").attr("disabled","");
  2068. $("#C5_FRETE").val("0,00");
  2069. //$("#C5_XTRANSP").removeAttr('disabled');
  2070. //$("#C5_XTRANSP").val("");
  2071. $("#select2-C5_XTRANSP-container").html("Selecione uma Transportadora");
  2072. } else {
  2073. if (cFrete != ""){
  2074. $("#C5_FRETE").attr("required","");
  2075. $("#C5_FRETE").attr("aria-required","true");
  2076. $("#C5_FRETE").removeAttr('disabled');
  2077. $("#C5_FRETE").focus();
  2078. //$("#C5_XTRANSP").removeAttr('disabled');
  2079. //$("#C5_XTRANSP").val("");
  2080. }
  2081. //Localiza a transportadora
  2082. /*
  2083. $.ajax({
  2084. url: "U_GetTransp.apw?PR=<%=cLCodLogin%>",
  2085. type: "POST",
  2086. data: 'tabela='+tabpreco,
  2087. async: false,
  2088. success:
  2089. function(transp) {
  2090. if (transp.indexOf('<META HTTP-EQUIV') >= 0 ) {
  2091. $("html").html(transp);
  2092. return;
  2093. }
  2094. if ( transp != "" ) {
  2095. //Preenche o campo da transportadora
  2096. document.getElementById('C5_XTRANSP').innerText = null;
  2097. $("#C5_XTRANSP").append(transp);
  2098. } else {
  2099. bootbox.alert('Cliente sem transportadora cadastrada!');
  2100. $("#C5_TPFRETE").val("S")
  2101. $("#select2-C5_TPFRETE-container").html("Sem Frete")
  2102. $("#C5_FRETE").removeAttr("required");
  2103. $("#C5_FRETE").removeAttr("aria-required");
  2104. $("#C5_FRETE").attr("disabled","");
  2105. $("#C5_XTRANSP").attr("disabled","");
  2106. $("#C5_FRETE").val("0,00");
  2107. $("#C5_XTRANSP").val("");
  2108. $("#select2-C5_XTRANSP-container").html("Selecione uma Transportadora");
  2109. }
  2110. }
  2111. });
  2112. */
  2113. //$("#select2-C5_XTRANSP-container").html("Selecione uma Transportadora");
  2114. }
  2115. TotalGeral();
  2116. }
  2117. /**
  2118. // Função para ver detalhes da linha
  2119. **/
  2120. function detalhePed(cItem){
  2121. var msg = "";
  2122. var produto = formataProd($("#C6_PRODUTO"+cItem).val());
  2123. var retorno = "";
  2124. var estoque = "";
  2125. var dialogTab = "";
  2126. if(produto == ""){
  2127. bootbox.alert("Selecione o produto para ver os detalhes!");
  2128. return false;
  2129. }
  2130. msg = '<div class="row form-group">'
  2131. msg +=' <header class="panel-heading">'
  2132. msg +=' <h2 class="panel-title">Detalhes da linha</h2>'
  2133. msg +=' </header>'
  2134. msg +=' <br>'
  2135. //Descrição do produto
  2136. msg +=' <div class="row form-group">'
  2137. msg +=' <div class="col-lg-1"></div>'
  2138. msg +=' <div class="col-lg-11">'
  2139. msg +=' <label class="control-label">Produto</label>'
  2140. msg +=' <div class="input-group">'
  2141. msg +=' <input class="form-control text-left" style="width: 240%;" value="'+$("#C6_PRODUTO"+cItem).val().split('- ')[1]+'" disabled>'
  2142. msg +=' </div>'
  2143. msg +=' </div>'
  2144. msg +=' </div>'
  2145. //IPI
  2146. msg +=' <div class="row form-group">'
  2147. msg +=' <div class="col-lg-1"></div>'
  2148. msg +=' <div class="col-lg-3">'
  2149. msg +=' <label class="control-label">IPI</label>'
  2150. msg +=' <div class="input-group">'
  2151. msg +=' <input class="form-control text-right" value="'+$("#VAL_IPI"+cItem).val()+'" disabled>'
  2152. msg +=' </div>'
  2153. msg +=' </div>'
  2154. //ICMS
  2155. msg +=' <div class="col-lg-3">'
  2156. msg +=' <label class="control-label">ICMS</label>'
  2157. msg +=' <div class="input-group">'
  2158. msg +=' <input class="form-control text-right" value="'+$("#VAL_ICMS"+cItem).val()+'" disabled>'
  2159. msg +=' </div>'
  2160. msg +=' </div>'
  2161. //ICMS ST
  2162. msg +=' <div class="col-lg-3">'
  2163. msg +=' <label class="control-label">ICMS ST</label>'
  2164. msg +=' <div class="input-group">'
  2165. msg +=' <input class="form-control text-right" value="'+$("#VAL_ST"+cItem).val()+'" disabled>'
  2166. msg +=' </div>'
  2167. msg +=' </div>'
  2168. msg +=' </div>'
  2169. msg +=' <div class="row form-group">'
  2170. msg +=' <div class="col-lg-1"></div>'
  2171. msg +=' <div class="col-lg-3">'
  2172. msg +=' <label class="control-label">% Comis 4</label>'
  2173. msg +=' <div class="input-group">'
  2174. msg +=' <input class="form-control text-right" onchange="javascript:validaComis('+cItem+', this)" value="'+$("#C6_COMIS4"+cItem).val()+'" disabled>'
  2175. msg +=' </div>'
  2176. msg +=' </div>'
  2177. msg +=' <div class="col-lg-3">'
  2178. msg +=' <label class="control-label">NCM</label>'
  2179. msg +=' <div class="input-group">'
  2180. msg +=' <input class="form-control text-left" value="'+$("#C6_POSIPI"+cItem).val()+'" disabled>'
  2181. msg +=' </div>'
  2182. msg +=' </div>'
  2183. msg +=' <div class="col-lg-3">'
  2184. msg +=' <label class="control-label">Valor Lista</label>'
  2185. msg +=' <div class="input-group">'
  2186. msg +=' <input class="form-control text-right" value="'+$("#C6_PRUNIT"+cItem).val()+'" disabled>'
  2187. msg +=' </div>'
  2188. msg +=' </div>'
  2189. msg +=' </div>'
  2190. msg +='</div>'
  2191. if(msg != ""){
  2192. bootbox.dialog({
  2193. title: '',
  2194. message: "<p>"+msg+"</p>",
  2195. backdrop: true,
  2196. buttons: {
  2197. ok: {
  2198. label: "OK"
  2199. }
  2200. }
  2201. });
  2202. }
  2203. }
  2204. //Remover linha
  2205. function removeItem(cItem){
  2206. //e.preventDefault();
  2207. //var btnRem = $(this);
  2208. cItem = parseInt(cItem);
  2209. bootbox.confirm({
  2210. title: "Exclusão da linha",
  2211. message: "Confirma a exclusão desta linha?",
  2212. buttons: {
  2213. cancel: {
  2214. label: 'Cancelar'
  2215. },
  2216. confirm: {
  2217. label: 'Confirmar'
  2218. }
  2219. },
  2220. callback: function (result) {
  2221. if (result){
  2222. if (cItem < 10 ){cItem = "0"+String(cItem)};
  2223. //Desabilita o botão
  2224. //btnRem.attr({ 'disabled': 'disabled' });
  2225. $("#C6_ITEM"+cItem).val("x");
  2226. $("#C6_PRODUTO"+cItem).val("");
  2227. $("#C6_QTDVEN"+cItem).val("1");
  2228. $("#C6_LOCAL"+cItem).val("");
  2229. $("#C6_PRUNIT"+cItem).val("0");
  2230. $("#iC6_PRCVEN"+cItem).val("0,00");
  2231. $("#C6_PRCVEN"+cItem).val("0,00");
  2232. $("#C6_XVALICM"+cItem).val("0,00");
  2233. $("#C6_XVALIPI"+cItem).val("0,00");
  2234. $("#C6_XICMST"+cItem).val("0,00");
  2235. $("#C6_VALOR"+cItem).val("0,00");
  2236. $("#linha"+cItem).hide();
  2237. //Atualiza o total geral
  2238. TotalGeral();
  2239. }
  2240. }
  2241. });
  2242. }
  2243. //Clique no botão pesquisar do Cliente
  2244. $('.btSearchCli').click(function(e) {
  2245. e.preventDefault();
  2246. getCliente($(this));
  2247. });
  2248. //Clique no botão pesquisar do Cliente
  2249. $('.btEndEntrega').click(function(e) {
  2250. e.preventDefault();
  2251. getEntrega($(this));
  2252. });
  2253. $("#datatable-editable").delegate( "button", "click", function( event ) {
  2254. event.preventDefault();
  2255. getProduto($(this));
  2256. });
  2257. /**
  2258. //Anexar
  2259. **/
  2260. $("#btnInfUpload").click(function() {
  2261. var obAnexo = $("#anexo");
  2262. var obArquivo = obAnexo.clone();
  2263. obArquivo.attr("id", "arquivo");
  2264. $("#frmInfUpload").append(obArquivo);
  2265. var data;
  2266. var contentType = "application/x-www-form-urlencoded";
  2267. var processData = true;
  2268. if ($('#frmInfUpload').attr('enctype') == 'multipart/form-data') {
  2269. data = new FormData($('#frmInfUpload').get(0));//seleciona classe form-horizontal adicionada na tag form do html
  2270. contentType = false;
  2271. processData = false;
  2272. } else {
  2273. data = $('#frmInfUpload').serialize();
  2274. }
  2275. $.ajax({
  2276. data: data,
  2277. type: $('#frmInfUpload').attr('method'),
  2278. url: $('#frmInfUpload').attr('action'),
  2279. contentType: contentType,
  2280. processData: processData,
  2281. success: function (response) {
  2282. //seu código apos sucesso
  2283. if( response == "Ok" ) {
  2284. window.location.reload();
  2285. } else {
  2286. bootbox.alert('Erro ao carregar arquivo');
  2287. }
  2288. },
  2289. error: function (exr, sender) {
  2290. bootbox.alert('Erro ao carregar pagina');
  2291. }
  2292. });
  2293. });
  2294. //Adicionar nova linha
  2295. $('#btAddItm').click(function(e) {
  2296. e.preventDefault();
  2297. var newLine = parseFloat($("#PROXIMO").val())+1;
  2298. var nItens = parseFloat($("#PROXIMO").val());
  2299. var linhaAtu = String(newLine);
  2300. var lRet = true;
  2301. var lGridOK = true;
  2302. var btnAdd = $(this);
  2303. var cCodProd;
  2304. var cItmOrc;
  2305. let aExtras = [];
  2306. let aFields = [];
  2307. if (parseInt(linhaAtu) < 10 ){linhaAtu = "0"+String(linhaAtu)};
  2308. //Desabilita o botão
  2309. btnAdd.attr({ 'disabled': 'disabled' });
  2310. //Valida o Grid
  2311. if (nItens == 99){
  2312. lRet = false;
  2313. $("#orc-informar").html();
  2314. new PNotify({
  2315. title: 'Quantidade máxima',
  2316. text: 'O Pedido atingiu a quantidade máxima de itens. Crie um novo Pedido.',
  2317. type: 'error',
  2318. });
  2319. btnAdd.removeAttr('disabled');
  2320. return false;
  2321. }
  2322. if (lRet == true) {
  2323. for (i = 1; i<=nItens; i++) {
  2324. cItem = String(i);
  2325. if (parseInt(i) < 10 ){cItem = "0"+String(i)};
  2326. cItmOrc = $("#C6_ITEM"+cItem).val();
  2327. if(cItmOrc != "x") {
  2328. cCodProd = formataProd($("#C6_PRODUTO"+cItem).val());
  2329. if ($('#C6_PRODUTO'+cItem).val() == "" || $('#C6_QTDVEN'+cItem).val() == ""){
  2330. lGridOK = false;
  2331. }
  2332. }
  2333. }
  2334. if (lGridOK == false){
  2335. lRet = false;
  2336. $("#orc-informar").html();
  2337. new PNotify({
  2338. title: 'Campo obrigatório',
  2339. text: 'Verifique o preenchimento dos campos Produto e Quantidade antes de incluir uma nova linha!',
  2340. type: 'error',
  2341. });
  2342. btnAdd.removeAttr('disabled');
  2343. //Força fechar a janela
  2344. if (lRet == false){
  2345. bootbox.hideAll();
  2346. }
  2347. return false;
  2348. }
  2349. }
  2350. //Cria a linha
  2351. if (lRet == true) {
  2352. if (linhaAtu.length < 2) {
  2353. linhaAtu = "0" + linhaAtu;
  2354. }
  2355. // Carrega os campos do grid
  2356. getFieldsGrid(aFields);
  2357. var tbl = document.getElementById('datatable-editable'), // table reference
  2358. row = tbl.insertRow(tbl.rows.length), // append table row
  2359. i;
  2360. // insert table cells to the new row
  2361. for (i = 0; i < tbl.rows[0].cells.length; i++) {
  2362. newCreateCell(row.insertCell(i), i, linhaAtu, tbl.rows[0].cells.length - 1, aFields[i]);
  2363. }
  2364. // Adiciona um ouvinte de eventos usando a delegação de eventos
  2365. $(document).on('focusout', '[data-row] input', function () {
  2366. // Captura o valor do campo C6_PRODUTO
  2367. var produtoDigitado = this.value;
  2368. // Obtém o numero da linha associado ao campo
  2369. var linhaAtu = $(this).data('row');
  2370. // Chama a função buscarProdutos
  2371. buscarProdutos(produtoDigitado, function (listaProdutos) {
  2372. // Aqui voce pode fazer algo com a lista de produtos, se necessario
  2373. });
  2374. });
  2375. //Adiciona a classe no ultimo td
  2376. $('tr:last').find('td:last').addClass('actions');
  2377. //Adiciona id na linha
  2378. $('tr:last').attr('id','linha'+linhaAtu);
  2379. $('tr:last').attr('class','odd');
  2380. //Atualiza a quantidade de linhas
  2381. $("#PROXIMO").val(linhaAtu);
  2382. //Habilita o botão para adicionar itens
  2383. btnAdd.removeAttr('disabled');
  2384. formate();
  2385. };
  2386. });
  2387. //Obtém os campos da linha
  2388. function getFieldsGrid(aFields) {
  2389. let aExtras = [];
  2390. /// Definicao de campos extras
  2391. // aExtras.push({"field": 'btnInfo',
  2392. // "element": "i",
  2393. // "attrs":[
  2394. // {"class": "fa fa-info fa-lg"},
  2395. // {"title": "Detalhes da linha"},
  2396. // {'onclick': 'detalhePed($(this).attr("id").substr(-2))'}
  2397. // ]
  2398. // });
  2399. aExtras.push({"field": 'btnExcl',
  2400. "element": "i",
  2401. "attrs":[
  2402. {"class": "fa fa-times-circle fa-lg"},
  2403. {"title": "Remover linha"},
  2404. {'onclick': 'removeItem($(this).attr("id").substr(-2))'}
  2405. ]
  2406. });
  2407. aExtras.push({"field": 'C6_PRUNIT',
  2408. "element": "input",
  2409. "attrs":[
  2410. {"type": "hidden"},
  2411. {"value": ""}
  2412. ]
  2413. });
  2414. aExtras.push({"field": 'C6_POSIPI',
  2415. "element": "input",
  2416. "attrs":[
  2417. {"type": "hidden"},
  2418. {"value": ""},
  2419. ]
  2420. });
  2421. aFields.push({"field": 'C6_COMIS4',
  2422. "element": "input",
  2423. "attrs":[
  2424. {"type": "hidden"},
  2425. {"value": ""},
  2426. ]
  2427. });
  2428. aExtras.push({"field": 'ALIQ_ICMS',
  2429. "element": "input",
  2430. "attrs":[
  2431. {"type": "hidden"},
  2432. {"value": "0"}
  2433. ]
  2434. });
  2435. aExtras.push({"field": 'ALIQ_IPI',
  2436. "element": "input",
  2437. "attrs":[
  2438. {"type": "hidden"},
  2439. {"value": "0"}
  2440. ]
  2441. });
  2442. aExtras.push({"field": 'ALIQ_ST',
  2443. "element": "input",
  2444. "attrs":[
  2445. {"type": "hidden"},
  2446. {"value": "0"}
  2447. ]
  2448. });
  2449. aExtras.push({"field": 'VAL_ICMS',
  2450. "element": "input",
  2451. "attrs":[
  2452. {"type": "hidden"},
  2453. {"value": "0"}
  2454. ]
  2455. });
  2456. aExtras.push({"field": 'VAL_IPI',
  2457. "element": "input",
  2458. "attrs":[
  2459. {"type": "hidden"},
  2460. {"value": "0"}
  2461. ]
  2462. });
  2463. aExtras.push({"field": 'VAL_ST',
  2464. "element": "input",
  2465. "attrs":[
  2466. {"type": "hidden"},
  2467. {"value": "0"}
  2468. ]
  2469. });
  2470. aExtras.push({"field": 'BASE_ICMS',
  2471. "element": "input",
  2472. "attrs":[
  2473. {"type": "hidden"},
  2474. {"value": "0"}
  2475. ]
  2476. });
  2477. aExtras.push({"field": 'BASE_ST',
  2478. "element": "input",
  2479. "attrs":[
  2480. {"type": "hidden"},
  2481. {"value": "0"}
  2482. ]
  2483. });
  2484. aExtras.push({"field": 'BASE_IPI',
  2485. "element": "input",
  2486. "attrs":[
  2487. {"type": "hidden"},
  2488. {"value": "0"}
  2489. ]
  2490. });
  2491. aExtras.push({"field": 'IMP_PRCTAB',
  2492. "element": "input",
  2493. "attrs":[
  2494. {"type": "hidden"},
  2495. {"value": "0"}
  2496. ]
  2497. });
  2498. aExtras.push({"field": 'QTD_EMB',
  2499. "element": "input",
  2500. "attrs":[
  2501. {"type": "hidden"},
  2502. {"value": "0"}
  2503. ]
  2504. });
  2505. aExtras.push({"field": 'QTDMIN',
  2506. "element": "input",
  2507. "attrs":[
  2508. {"type": "hidden"},
  2509. {"value": "0"}
  2510. ]
  2511. });
  2512. aExtras.push({"field": 'GRUPO',
  2513. "element": "input",
  2514. "attrs":[
  2515. {"type": "hidden"},
  2516. {"value": ""}
  2517. ]
  2518. });
  2519. aExtras.push({"field": 'VENCIMENTO',
  2520. "element": "input",
  2521. "attrs":[
  2522. {"type": "hidden"},
  2523. {"value": ""}
  2524. ]
  2525. });
  2526. /// Definicao de campos da tabela
  2527. aFields.push({"field": 'C6_ITEM' ,
  2528. "showtd": true,
  2529. "element": "input",
  2530. "attrs": [
  2531. {"type": "text"},
  2532. {"class": "form-control text-left input-block"},
  2533. {"disabled": "disabled"},
  2534. {"value": ""}
  2535. ],
  2536. "aftercreate": function(newLine) {
  2537. $("#C6_ITEM"+newLine).val(newLine);
  2538. }
  2539. });
  2540. aFields.push({"field": 'C6_PRODUTO',
  2541. "showtd": true
  2542. });
  2543. aFields.push({"field": 'C6_UM',
  2544. "showtd": true,
  2545. "element": "input",
  2546. "attrs":[
  2547. {"type": "text"},
  2548. {"class": "form-control text-left"},
  2549. {"disabled": "disabled"},
  2550. {"value": ""},
  2551. ]
  2552. });
  2553. aFields.push({"field": 'C6_QTDVEN' ,
  2554. "showtd": true,
  2555. "element": "input",
  2556. "attrs":[
  2557. {"type": "text"},
  2558. {"class": "form-control text-right only-numbers"},
  2559. {"disabled": "disabled"},
  2560. {"value": ""},
  2561. {"placeholder": "0"},
  2562. {'required': 'required'},
  2563. {'aria-required': 'true'},
  2564. {"onblur": 'javascript:VldQtd($(this).attr("id").substr(-2))'},
  2565. {'onkeyup': 'javascript:TotalItem($(this).attr("id").substr(-2))'}
  2566. ]
  2567. });
  2568. aFields.push({"field": 'C6_PRCVEN' ,
  2569. "showtd": true,
  2570. "element": "input",
  2571. "attrs":[
  2572. {"type": "text"},
  2573. {"class": "form-control text-right input-block"},
  2574. {"disabled": "disabled"},
  2575. {"value": ""}
  2576. ]
  2577. });
  2578. aFields.push({"field": 'C6_VALOR' ,
  2579. "showtd": true,
  2580. "element": "input",
  2581. "attrs":[
  2582. {"type": "text"},
  2583. {"class": "form-control text-right input-block"},
  2584. {"disabled": "disabled"},
  2585. {"value": ""}
  2586. ]
  2587. });
  2588. aFields.push({"field": 'C6_ENTREG',
  2589. "showtd": true,
  2590. "element": "input",
  2591. "attrs":[
  2592. {"type": "text"},
  2593. {"class": "form-control text-left"},
  2594. {"disabled": "disabled"},
  2595. {"value": ""},
  2596. ]
  2597. });
  2598. aFields.push({"field": 'C6_OPER',
  2599. "showtd": true,
  2600. "element": "input",
  2601. "attrs":[
  2602. {"type": "text"},
  2603. {"disabled": "disabled"},
  2604. {"value": ""},
  2605. {"class": "form-control text-left input-block"},
  2606. ]
  2607. });
  2608. aFields.push({"field": 'C6_TES',
  2609. "showtd": true,
  2610. "element": "input",
  2611. "attrs":[
  2612. {"type": "text"},
  2613. {"disabled": "disabled"},
  2614. {"value": ""},
  2615. {"class": "form-control text-left input-block"},
  2616. ]
  2617. });
  2618. aFields.push({"field": 'C6_CF',
  2619. "showtd": true,
  2620. "element": "input",
  2621. "attrs":[
  2622. {"type": "text"},
  2623. {"disabled": "disabled"},
  2624. {"value": ""},
  2625. {"class": "form-control text-left input-block"},
  2626. ]
  2627. });
  2628. aFields.push({"field": 'C6_COMIS2',
  2629. "showtd": true,
  2630. "element": "input",
  2631. "attrs":[
  2632. {"type": "text"},
  2633. {"class": "form-control text-right percentual"},
  2634. {"disabled": "disabled"},
  2635. {"value": "0"},
  2636. {"placeholder": "0,00"},
  2637. {'maxlength': '7'},
  2638. ]
  2639. });
  2640. aFields.push({"field": 'C6_COMIS3',
  2641. "showtd": true,
  2642. "element": "input",
  2643. "attrs":[
  2644. {"type": "text"},
  2645. {"class": "form-control text-right percentual"},
  2646. {"disabled": "disabled"},
  2647. {"value": "0"},
  2648. {"placeholder": "0,00"},
  2649. {'maxlength': '7'},
  2650. ]
  2651. });
  2652. aFields.push({"field": 'C6_PEDCLI',
  2653. "showtd": true,
  2654. "element": "input",
  2655. "attrs":[
  2656. {"type": "text"},
  2657. {"value": ""},
  2658. {"class": "form-control text-left"},
  2659. ]
  2660. });
  2661. aFields.push({"field": 'C6_IPEDCLI',
  2662. "showtd": true,
  2663. "element": "input",
  2664. "attrs":[
  2665. {"type": "text"},
  2666. {"value": ""},
  2667. {"class": "form-control text-left"},
  2668. ]
  2669. });
  2670. aFields.push({"field": 'C6_XPRCIMP',
  2671. "showtd": false,
  2672. "element": "input",
  2673. "attrs":[
  2674. {"type": "text"},
  2675. {"class": "form-control text-right input-block"},
  2676. {"disabled": "disabled"},
  2677. {"value": ""}
  2678. ]
  2679. });
  2680. aFields.push({"field": 'iC6_PRCVEN',
  2681. "showtd": false,
  2682. "element": "input",
  2683. "attrs":[
  2684. {"type": "text"},
  2685. {"class": "form-control text-right input-block"},
  2686. {"disabled": "disabled"},
  2687. {"value": ""}
  2688. ]
  2689. });
  2690. aFields.push({"field": 'C6_CUSTO',
  2691. "showtd": false,
  2692. "element": "input",
  2693. "attrs":[
  2694. {"type": "text"},
  2695. {"class": "form-control text-right"},
  2696. {"disabled": "disabled"}
  2697. ]
  2698. });
  2699. // "aftercreate": "function x"
  2700. aFields.push({"field": 'C6_XVALIPI',
  2701. "showtd": false,
  2702. "element": "input",
  2703. "attrs":[
  2704. {"type": "text"},
  2705. {"class": "form-control text-right input-block"},
  2706. {"disabled": "disabled"},
  2707. {"value": ""}
  2708. ]
  2709. });
  2710. aFields.push({"field": 'C6_XVALICM',
  2711. "showtd": false,
  2712. "element": "input",
  2713. "attrs":[
  2714. {"type": "text"},
  2715. {"class": "form-control text-right input-block"},
  2716. {"disabled": "disabled"},
  2717. {"value": ""}
  2718. ]
  2719. });
  2720. aFields.push({"field": 'C6_XICMST' ,
  2721. "showtd": false,
  2722. "element": "input",
  2723. "attrs":[
  2724. {"type": "text"},
  2725. {"class": "form-control text-right input-block"},
  2726. {"disabled": "disabled"},
  2727. {"value": ""}
  2728. ]
  2729. });
  2730. aFields.push({"field": 'C6_DESCONT',
  2731. "showtd": false,
  2732. "element": "input",
  2733. "attrs":[
  2734. {"type": "text"},
  2735. {"class": "form-control text-right percentual"},
  2736. {"disabled": "disabled"},
  2737. {"value": ""},
  2738. {"placeholder": "0,00"},
  2739. {'maxlength': '7'},
  2740. {"onblur": 'javascript:VldValor($(this).attr("id").substr(-2))'},
  2741. {'onkeyup': 'javascript:TotalItem($(this).attr("id").substr(-2))'}
  2742. ]
  2743. });
  2744. // aFields.push({"field": 'C6_NOMDIRE',
  2745. // "showtd": false,
  2746. // "element": "input",
  2747. // "attrs":[
  2748. // {"type": "text"},
  2749. // {"class": "form-control text-left"},
  2750. // {"disabled": "disabled"},
  2751. // {"value": ""},
  2752. // {'maxlength': '12'}
  2753. // ]
  2754. // });
  2755. aFields.push({"field": 'VAL_COM' ,
  2756. "showtd": false,
  2757. "element": "input",
  2758. "attrs":[
  2759. {"type": "text"},
  2760. {"class": "form-control text-right input-block"},
  2761. {"disabled": "disabled"},
  2762. {"value": ""}
  2763. ]
  2764. });
  2765. aFields.push({"field": 'botoes' ,
  2766. "showtd": true,
  2767. "element": "extras",
  2768. "extras": aExtras
  2769. });
  2770. }
  2771. // Criacao da linha da tabela
  2772. function newCreateCell(objCell, ncol, newLine, nTam, objCrea) {
  2773. // Criacao dos elementos
  2774. if ("extras" !== objCrea["element"]) {
  2775. if (objCrea["field"] == "C6_PRODUTO") {
  2776. //icone de pesquisa
  2777. let obji = document.createElement("i");
  2778. obji.setAttribute("class","fa fa-search");
  2779. obji.setAttribute("alt","Pesquisar");
  2780. //botão do icone de pesquisa
  2781. let objb = document.createElement("button");
  2782. objb.setAttribute("class","btSearch");
  2783. objb.setAttribute("id","btSearch"+newLine);
  2784. objb.appendChild(obji); //apenda o icone no botão
  2785. //input do produto
  2786. let objinp = document.createElement("input");
  2787. objinp.setAttribute("type","text");
  2788. objinp.setAttribute("class","form-control smsediticon");
  2789. objinp.setAttribute("placeholder","Digite o código ou descrição...");
  2790. objinp.setAttribute("name","C6_PRODUTO" + newLine);
  2791. objinp.setAttribute("id","C6_PRODUTO" + newLine);
  2792. objinp.setAttribute("aria-required","true");
  2793. objinp.setAttribute("data-live-search","true");
  2794. objinp.setAttribute("autocomplete","off");
  2795. objinp.setAttribute("value","");
  2796. //div flexContainer
  2797. let objDivFlex = document.createElement("div");
  2798. objDivFlex.setAttribute("class","flexContainer");
  2799. objDivFlex.appendChild(objinp);
  2800. objDivFlex.appendChild(objb);
  2801. //div com tamanho da coluna
  2802. let objDivCol = document.createElement("div");
  2803. objDivCol.setAttribute("class","col-md-12");
  2804. objDivCol.appendChild(objDivFlex);
  2805. //div principal
  2806. let objDivForm = document.createElement("div");
  2807. objDivForm.setAttribute("class","form-group");
  2808. objDivForm.appendChild(objDivCol);
  2809. objCell.appendChild(objDivForm);
  2810. } else {
  2811. let objElem = document.createElement(objCrea["element"]);
  2812. objElem.setAttribute('id', objCrea["field"] + newLine);
  2813. if ("input.select.".includes(objCrea["element"]+".")) {
  2814. objElem.setAttribute('name', objCrea["field"] + newLine);
  2815. }
  2816. if (objCrea["attrs"]) {
  2817. for (let attr of objCrea["attrs"]) {
  2818. for (let [key, value] of Object.entries(attr)) {
  2819. objElem.setAttribute(key, value);
  2820. }
  2821. }
  2822. }
  2823. if (objCrea["beforeadd"]) {
  2824. objCrea["beforeadd"](objElem, newLine);
  2825. }
  2826. objCell.appendChild(objElem);
  2827. if (objCrea["aftercreate"]) {
  2828. objCrea["aftercreate"](newLine);
  2829. }
  2830. }
  2831. } else {
  2832. // Inclusao dos campos extras na ultima coluna
  2833. for (let extra of objCrea["extras"]) {
  2834. let objElem = document.createElement(extra["element"]);
  2835. objElem.setAttribute('id', extra["field"] + newLine);
  2836. if (extra["element"] == "input") {
  2837. objElem.setAttribute('name', extra["field"] + newLine);
  2838. }
  2839. if (extra["attrs"]) {
  2840. for (let attr of extra["attrs"]) {
  2841. for (let [key, value] of Object.entries(attr)) {
  2842. objElem.setAttribute(key, value);
  2843. }
  2844. }
  2845. }
  2846. objCell.appendChild(objElem);
  2847. }
  2848. }
  2849. if (!objCrea.showtd) {
  2850. $('tr:last').find('td:last').attr('hidden','');
  2851. }
  2852. }
  2853. function validaComis(cItemAtu, elemento){
  2854. var comis2 = parseFloat($("#C6_COMIS2"+cItemAtu).val())
  2855. var comis3 = parseFloat($("#C6_COMIS3"+cItemAtu).val())
  2856. var comis4 = parseFloat($("#C6_COMIS4"+cItemAtu).val())
  2857. var comisProd = parseFloat($("#B1_COMIS"+cItemAtu).val())
  2858. if((comis2 + comis3 + comis4) > comisProd){
  2859. bootbox.alert({
  2860. title: 'Comissão',
  2861. message: "<p>A somatória de percentual de comissão não pode ultrapassar a comissão do produto: "+comisProd+"%. </p>",
  2862. backdrop: true,
  2863. callback: function () {
  2864. elemento.value = '0'
  2865. elemento.focus()
  2866. }
  2867. });
  2868. }
  2869. }
  2870. //Salvar o Pedido
  2871. $('#btSalvar').click(function() {
  2872. var lRet = true
  2873. var i = 0;
  2874. var nItens = parseFloat($("#PROXIMO").val());
  2875. var lGrid = true;
  2876. var lGrid1 = true;
  2877. var cCodProd;
  2878. var cItmOrc;
  2879. var btnSlv = $(this);
  2880. var cGrupo = "";
  2881. var dialogOrc = bootbox.dialog({
  2882. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Validando Pedido. Aguarde...</p>',
  2883. closeButton: false
  2884. });
  2885. //Desabilita o botao
  2886. btnSlv.attr({ 'disabled': 'disabled' });
  2887. $.ajax({
  2888. url: "U_VerSessao.apw?PR=<%=cLCodLogin%>",
  2889. type: "POST",
  2890. async: false,
  2891. success:
  2892. function(retorno) {
  2893. if (retorno.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  2894. $("html").html(retorno);
  2895. return;
  2896. }
  2897. if (retorno == "nok"||retorno == ''||retorno.toUpperCase().indexOf("EXPIRES") != -1){
  2898. $("#orc-informar").html();
  2899. bootbox.alert('Não foi possível realizar a operação pois a sessão foi fechada. Faça login novamente.');
  2900. lRet = false;
  2901. btnSlv.removeAttr('disabled');
  2902. dialogOrc.modal('hide');
  2903. }
  2904. }
  2905. });
  2906. /**
  2907. Valida os campos obrigatorios
  2908. **/
  2909. //Cliente
  2910. cliente = formataCli($("#C5_CLIENTE").val());
  2911. if (cliente == "") {
  2912. lRet = false;
  2913. $("#orc-informar").html();
  2914. new PNotify({
  2915. title: 'Campo obrigatório',
  2916. text: 'Preencha o campo Cliente!',
  2917. type: 'error',
  2918. });
  2919. btnSlv.removeAttr('disabled');
  2920. dialogOrc.modal('hide');
  2921. $("#C5_CLIENTE").focus();
  2922. }
  2923. /**
  2924. Valida os campos obrigatorios
  2925. **/
  2926. //Cliente
  2927. cliente = formataCli($("#C5_CLIENTE").val());
  2928. if (cliente == "") {
  2929. lRet = false;
  2930. $("#orc-informar").html();
  2931. new PNotify({
  2932. title: 'Campo obrigatório',
  2933. text: 'Preencha o campo Cliente!',
  2934. type: 'error',
  2935. });
  2936. btnSlv.removeAttr('disabled');
  2937. dialogOrc.modal('hide');
  2938. $("#C5_CLIENTE").focus();
  2939. }
  2940. //Contato do Cliente
  2941. if (lRet == true && $("#C5_XCONTAT").val() == "") {
  2942. lRet = false;
  2943. $("#orc-informar").html();
  2944. new PNotify({
  2945. title: 'Campo obrigatório',
  2946. text: 'Preencha o campo Contato do Cliente!',
  2947. type: 'error',
  2948. });
  2949. btnSlv.removeAttr('disabled');
  2950. dialogOrc.modal('hide');
  2951. $("#C5_XCONTAT").focus();
  2952. }
  2953. //Contato do Cliente - DDD
  2954. if (lRet == true && $("#C5_XCONDDD").val() == "") {
  2955. lRet = false;
  2956. $("#orc-informar").html();
  2957. new PNotify({
  2958. title: 'Campo obrigatório',
  2959. text: 'Preencha o campo DDD do Contato!',
  2960. type: 'error',
  2961. });
  2962. btnSlv.removeAttr('disabled');
  2963. dialogOrc.modal('hide');
  2964. $("#C5_XCONDDD").focus();
  2965. }
  2966. //Contato do Cliente - Telefone
  2967. if (lRet == true && $("#C5_XCONTEL").val() == "") {
  2968. lRet = false;
  2969. $("#orc-informar").html();
  2970. new PNotify({
  2971. title: 'Campo obrigatório',
  2972. text: 'Preencha o campo Telefone do Contato!',
  2973. type: 'error',
  2974. });
  2975. btnSlv.removeAttr('disabled');
  2976. dialogOrc.modal('hide');
  2977. $("#C5_XCONTEL").focus();
  2978. }
  2979. //Cliente de entrega
  2980. if (lRet == true && $("#C5_CLIENT").val() == "") {
  2981. lRet = false;
  2982. $("#orc-informar").html();
  2983. new PNotify({
  2984. title: 'Campo obrigatório',
  2985. text: 'Preencha o campo Cliente de Entrega!',
  2986. type: 'error',
  2987. });
  2988. btnSlv.removeAttr('disabled');
  2989. dialogOrc.modal('hide');
  2990. $("#C5_CLIENT").focus();
  2991. }
  2992. //Tabela de preço
  2993. if (lRet == true && $("#C5_TABELA").val() == "") {
  2994. lRet = false;
  2995. $("#orc-informar").html();
  2996. new PNotify({
  2997. title: 'Campo obrigatório',
  2998. text: 'Falha ao localizar a Tabela de Preço!',
  2999. type: 'error',
  3000. });
  3001. btnSlv.removeAttr('disabled');
  3002. dialogOrc.modal('hide');
  3003. $("#C5_TABELA").focus();
  3004. }
  3005. //Data de Entrega
  3006. /*
  3007. if (lRet == true && $("#C6_ENTREG").val() == "") {
  3008. lRet = false;
  3009. $("#orc-informar").html();
  3010. new PNotify({
  3011. title: 'Campo obrigatório',
  3012. text: 'Preencha o campo Previsão de Faturamento!',
  3013. type: 'error',
  3014. });
  3015. btnSlv.removeAttr('disabled');
  3016. dialogOrc.modal('hide');
  3017. $("#C6_ENTREGA").focus();
  3018. }
  3019. */
  3020. //Condição de pagamento
  3021. if (lRet == true && $("#C5_CONDPAG").val() == "") {
  3022. lRet = false;
  3023. $("#orc-informar").html();
  3024. new PNotify({
  3025. title: 'Campo obrigatório',
  3026. text: 'Preencha o campo Condição de Pagamento!',
  3027. type: 'error',
  3028. });
  3029. btnSlv.removeAttr('disabled');
  3030. dialogOrc.modal('hide');
  3031. $("#C5_CONDPAG").focus();
  3032. }
  3033. //Oportunidade
  3034. // if (lRet == true && $("#C5_NROPOR").val() == "") {
  3035. // lRet = false;
  3036. // $("#orc-informar").html();
  3037. // new PNotify({
  3038. // title: 'Campo obrigatório',
  3039. // text: 'Preencha o campo Oportunidade!',
  3040. // type: 'error',
  3041. // });
  3042. // btnSlv.removeAttr('disabled');
  3043. // dialogOrc.modal('hide');
  3044. // $("#C5_NROPOR").focus();
  3045. // }
  3046. //Nome da Obra
  3047. // if (lRet == true && $("#C5_OBRA").val() == "") {
  3048. // lRet = false;
  3049. // $("#orc-informar").html();
  3050. // new PNotify({
  3051. // title: 'Campo obrigatório',
  3052. // text: 'Preencha o campo Nome da Obra!',
  3053. // type: 'error',
  3054. // });
  3055. // btnSlv.removeAttr('disabled');
  3056. // dialogOrc.modal('hide');
  3057. // $("#C5_OBRA").focus();
  3058. // }
  3059. //Status da obra
  3060. // if (lRet == true && $("#C5_VEND6").val() == "") {
  3061. // lRet = false;
  3062. // $("#orc-informar").html();
  3063. // new PNotify({
  3064. // title: 'Campo obrigatório',
  3065. // text: 'Preencha o campo Status da Obra!',
  3066. // type: 'error',
  3067. // });
  3068. // btnSlv.removeAttr('disabled');
  3069. // dialogOrc.modal('hide');
  3070. // $("#C5_VEND6").focus();
  3071. // }
  3072. //Previsão de fechamento
  3073. // if (lRet == true && $("#C5_TERMOME").val() == "") {
  3074. // lRet = false;
  3075. // $("#orc-informar").html();
  3076. // new PNotify({
  3077. // title: 'Campo obrigatório',
  3078. // text: 'Preencha o campo Previsão de Fechamento!',
  3079. // type: 'error',
  3080. // });
  3081. // btnSlv.removeAttr('disabled');
  3082. // dialogOrc.modal('hide');
  3083. // $("#C5_TERMOME").focus();
  3084. // }
  3085. //Estudo luminotécnico
  3086. // if (lRet == true && $("#CJ_LUMINOT").val() == "") {
  3087. // lRet = false;
  3088. // $("#orc-informar").html();
  3089. // new PNotify({
  3090. // title: 'Campo obrigatório',
  3091. // text: 'Preencha o campo Estudo Luminotécnico!',
  3092. // type: 'error',
  3093. // });
  3094. // btnSlv.removeAttr('disabled');
  3095. // dialogOrc.modal('hide');
  3096. // $("#CJ_LUMINOT").focus();
  3097. // } else {
  3098. // if($("#CJ_LUMINOT").val() == "1"){
  3099. // if($("#C5_REGLUMI").val() == ""){
  3100. // lRet = false;
  3101. // $("#orc-informar").html();
  3102. // new PNotify({
  3103. // title: 'Campo obrigatório',
  3104. // text: 'Preencha o campo Número do Estudo Luminotécnico!',
  3105. // type: 'error',
  3106. // });
  3107. // btnSlv.removeAttr('disabled');
  3108. // dialogOrc.modal('hide');
  3109. // $("#C5_REGLUMI").focus();
  3110. // }
  3111. // }
  3112. // }
  3113. //Segmento
  3114. // if (lRet == true && $("#CJ_SEGMENT").val() == "") {
  3115. // lRet = false;
  3116. // $("#orc-informar").html();
  3117. // new PNotify({
  3118. // title: 'Campo obrigatório',
  3119. // text: 'Preencha o campo Segmento!',
  3120. // type: 'error',
  3121. // });
  3122. // btnSlv.removeAttr('disabled');
  3123. // dialogOrc.modal('hide');
  3124. // $("#CJ_SEGMENT").focus();
  3125. // }
  3126. //Regional
  3127. // if (lRet == true && $("#C5_REGIAO").val() == "") {
  3128. // lRet = false;
  3129. // $("#orc-informar").html();
  3130. // new PNotify({
  3131. // title: 'Campo obrigatório',
  3132. // text: 'Preencha o campo Regional!',
  3133. // type: 'error',
  3134. // });
  3135. // btnSlv.removeAttr('disabled');
  3136. // dialogOrc.modal('hide');
  3137. // $("#C5_REGIAO").focus();
  3138. // }
  3139. //Vendedor 2
  3140. if (lRet == true && $("#C5_VEND").val() == "") {
  3141. lRet = false;
  3142. $("#orc-informar").html();
  3143. new PNotify({
  3144. title: 'Campo obrigatório',
  3145. text: 'Preencha o campo Vendedor 2!',
  3146. type: 'error',
  3147. });
  3148. btnSlv.removeAttr('disabled');
  3149. dialogOrc.modal('hide');
  3150. $("#C5_VEND").focus();
  3151. }
  3152. //Negociadora
  3153. if (lRet == true && $("#C5_NEGOCIA").val() == "") {
  3154. lRet = false;
  3155. $("#orc-informar").html();
  3156. new PNotify({
  3157. title: 'Campo obrigatório',
  3158. text: 'Preencha o campo Negociadora!',
  3159. type: 'error',
  3160. });
  3161. btnSlv.removeAttr('disabled');
  3162. dialogOrc.modal('hide');
  3163. $("#C5_NEGOCIA").focus();
  3164. }
  3165. //Frete
  3166. if (lRet == true && $("#C5_FRETE").val() != "") {
  3167. cTpFrete = $("#C5_TPFRETE").val();
  3168. nTotalOrc = $("#TOTAL_ITENS").maskMoney('unmasked')[0];
  3169. freteMinimo = $("#FRETEMIN").val();
  3170. ufEntrega = $("#C5_UFENT").val().substr(0,2);
  3171. munEntrega = $("#C5_UFENT").val().substr(1,5);
  3172. if (freteMinimo != ""){
  3173. if(nTotalOrc <= freteMinimo && (cTpFrete == "C" || cTpFrete == "")){
  3174. $.ajax({
  3175. url: "U_FreteMinimo.apw?PR=<%=cLCodLogin%>",
  3176. data: 'UFEnt='+ufEntrega+'&MunEntrega='+munEntrega,
  3177. type: "POST",
  3178. async: false,
  3179. success:
  3180. function(frete) {
  3181. if (frete.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  3182. $("html").html(frete);
  3183. return;
  3184. } else {
  3185. if (parseInt(frete) > 0) {
  3186. $("#C5_FRETE").val(frete);
  3187. TotalGeral();
  3188. }
  3189. }
  3190. }
  3191. });
  3192. } else {
  3193. $("#C5_FRETE").val(0);
  3194. }
  3195. }
  3196. }
  3197. //Grid
  3198. if (lRet == true) {
  3199. var nPrcTab = 0;
  3200. var nPrcVen = 0;
  3201. var lVencido = false;
  3202. var cGrpEsp = 'PE,PEL,PED,PI';
  3203. var cMsLumEspL = '';
  3204. for (i = 1; i<=nItens; i++) {
  3205. cItem = String(i);
  3206. if (parseInt(i) < 10 ){cItem = "0"+String(i)};
  3207. cItmOrc = $("#C6_ITEM"+cItem).val();
  3208. if(cItmOrc != "x") {
  3209. cCodProd = formataProd($("#C6_PRODUTO"+cItem).val());
  3210. qtd = parseFloat($("#C6_QTDVEN"+cItem).val().replace('.',"").replace(",","."));
  3211. nTotalOrc = $("#C6_TOTAL"+cItem).val();
  3212. nPrcTab += $("#iC6_PRCVEN"+cItem).val().replace('.',"").replace(",",".") * qtd;
  3213. nPrcVen += $("#C6_PRCVEN"+cItem).val().replace('.',"").replace(",",".") * qtd;
  3214. // nPrcTab += $("#iC6_PRCVEN"+cItem).maskMoney('unmasked')[0] * qtd;
  3215. // nPrcVen += $("#C6_PRCVEN"+cItem).maskMoney('unmasked')[0] * qtd;
  3216. //Valida o preenchimento dos campos produto e quantidade
  3217. if (cCodProd == "" || $('#C6_QTDVEN'+cItem).val() == "" || nTotalOrc == ""){
  3218. lGrid = false;
  3219. } else {
  3220. cGrupo = $("#GRUPO"+cItem).val();
  3221. vencido = $("#VENCIMENTO"+cItem).val();
  3222. //Valida itens de grupos especiais
  3223. if(cGrpEsp.includes(cGrupo) && vencido == '1' ){
  3224. lVencido = true;
  3225. cMsLumEspL += cItmOrc+';'+cCodProd+';'+$("#C6_QTDVEN"+cItem).val()+'|'
  3226. }
  3227. }
  3228. }
  3229. }
  3230. if (lGrid == false){
  3231. lRet = false;
  3232. $("#orc-informar").html();
  3233. new PNotify({
  3234. title: 'Campo obrigatório',
  3235. text: 'Verifique o preenchimento dos campos Produto, Quantidade e Valor!',
  3236. type: 'error',
  3237. });
  3238. btnSlv.removeAttr('disabled');
  3239. dialogOrc.modal('hide');
  3240. } else {
  3241. $.ajax({
  3242. url: "U_VldDscMax.apw?PR=<%=cLCodLogin%>",
  3243. data: 'vlrTabela='+nPrcTab+'&vlrVenda='+nPrcVen+'&condpag='+$("#C5_CONDPAG").val()+"&descDir="+$('#C5_DSDIRET').val(),
  3244. cache: false,
  3245. type: "POST",
  3246. async: false,
  3247. success:
  3248. function(retorno) {
  3249. if (retorno.toUpperCase().indexOf('META HTTP-EQUIV') >= 0 ) {
  3250. $("html").html(retorno);
  3251. return;
  3252. }
  3253. if (retorno.substr(0, 3) == "NOK"){
  3254. aDesc = retorno.split('|#|');
  3255. cMsg = "O Pedido excedeu a Política de Descontos. Entre em contato com a Supervisão ou Diretoria.<br>";
  3256. cMsg += "Desconto concedido: <b>"+aDesc[0]+"</b><br>";
  3257. cMsg += "Desconto máximo permitido: <b>"+aDesc[1]+"</b>";
  3258. bootbox.alert(cMsg);
  3259. lRet = false;
  3260. }
  3261. }
  3262. });
  3263. }
  3264. }
  3265. //Verifica os itens especiais vencidos antes de salvar o formulário
  3266. if(lRet == true && lVencido){
  3267. msg = 'Existem códigos especiais com preços desatualizados. <br>';
  3268. msg += 'Deseja enviar e-mail solicitando atualização?';
  3269. bootbox.confirm({
  3270. title: 'Códigos especiais',
  3271. message: "<p>"+msg+"</p>",
  3272. backdrop: true,
  3273. buttons: {
  3274. cancel: {
  3275. label: 'Não'
  3276. },
  3277. confirm: {
  3278. label: 'Sim'
  3279. }
  3280. },
  3281. callback: function (result) {
  3282. if (result){
  3283. filorc = $("#C5_FILIAL").val();
  3284. numorc = $("#C5_NUM").val();
  3285. obra = $("#C5_OBRA").val();
  3286. //Chama a função para envio de email
  3287. $.ajax({
  3288. url: "U_AtuPreco.apw?PR=<%=cLCodLogin%>",
  3289. type: "POST",
  3290. data: 'filial='+filorc+'&orcto='+numorc+'&obra='+obra+'&itens='+cMsLumEspL,
  3291. async: false
  3292. });
  3293. }
  3294. }
  3295. });
  3296. }
  3297. //Valida a condição de pagamento
  3298. if (lRet == true){
  3299. dialogOrc.modal('hide');
  3300. //Submete o formulário
  3301. salvarOrc(btnSlv);
  3302. }
  3303. })
  3304. //Submete formulario
  3305. function salvarOrc(btnSlv){
  3306. var numorc = "";
  3307. //if (lRet == true){
  3308. var dialogSlv = bootbox.dialog({
  3309. message: '<p class="text-center"><i class="fa fa-spin fa-spinner"></i>&nbsp;&nbsp;Salvando Pedido... Aguarde...</p>',
  3310. closeButton: false
  3311. });
  3312. //busca os itens cadastrados
  3313. var ITENS = "";
  3314. var i = 0;
  3315. var nItens = parseFloat($("#PROXIMO").val());
  3316. var cCodProd;
  3317. var cItmOrc;
  3318. var cDescAcresc = "0";
  3319. for (i = 1; i<=nItens; i++) {
  3320. cItem = String(i);
  3321. if (parseInt(i) < 10 ){cItem = "0"+String(i)};
  3322. cItmOrc = $("#C6_ITEM"+cItem).val();
  3323. if(cItmOrc != "x") {
  3324. ITENS+= formataProd($('#C6_PRODUTO'+cItem).val())+';'; //1
  3325. ITENS+= $('#C6_QTDVEN'+cItem).val()+';'; //2
  3326. ITENS+= $('#C6_PRCVEN'+cItem).val()+';'; //3
  3327. ITENS+= $('#C6_UM'+cItem).val()+';'; //4
  3328. ITENS+= $('#C6_PRUNIT'+cItem).val()+';'; //5
  3329. ITENS+= $('#C6_VALOR'+cItem).val()+';'; //6
  3330. ITENS+= $('#C6_ENTREG'+cItem).val()+';'; //7
  3331. ITENS+= $('#C6_OPER'+cItem).val()+';'; //8
  3332. ITENS+= $('#C6_TES'+cItem).val()+';'; //9
  3333. ITENS+= $('#C6_CF'+cItem).val()+';'; //10
  3334. ITENS+= $('#C6_POSIPI'+cItem).val()+';'; //11
  3335. ITENS+= $('#C6_COMIS2'+cItem).val()+';'; //12
  3336. ITENS+= $('#C6_COMIS3'+cItem).val()+';'; //13
  3337. ITENS+= $('#C6_COMIS4'+cItem).val()+';'; //14
  3338. ITENS+= $('#C6_PEDCLI'+cItem).val()+';'; //15
  3339. ITENS+= $('#C6_IPEDCLI'+cItem).val()+'||' //16
  3340. }
  3341. }
  3342. objDados = {
  3343. C5_NUM: $('#C5_NUM').val(),
  3344. C5_FILIAL: $('#C5_FILIAL').val(),
  3345. C5_CLIENTE: formataCli($('#C5_CLIENTE').val()),
  3346. C5_CLIENT: $('#C5_CLIENT').val(),
  3347. C5_CONDPAG: $('#C5_CONDPAG').val(),
  3348. C5_TIPOCLI: $('#C5_TIPOCLI').val(), //consulta
  3349. C5_TIPOLUM: $('#C5_TIPOLUM').val(),
  3350. C5_VEND1: $('#C5_VEND1').val(),
  3351. C5_TPFRETE: $('#C5_TPFRETE').val(),
  3352. C5_TRANSP: $('#C5_TRANSP').val(),
  3353. C5_REDESP: $('#C5_REDESP').val(),
  3354. C5_FRETE: $('#C5_FRETE').val(),
  3355. C5_DATENTR: $('#C5_DATENTR').val(),
  3356. C5_FATPARC: $('#C5_FATPARC').val(),
  3357. C5_NEGOCIA: $('#C5_NEGOCIA').val(),
  3358. C5_ESTAGIO: $('#C5_ESTAGIO').val(),
  3359. C5_MAILNF: $('#C5_MAILNF').val(),
  3360. C5_VEND2: $('#C5_VEND2').val(),
  3361. C5_VEND3: $('#C5_VEND3').val(),
  3362. C5_VEND4: $('#C5_VEND4').val(),
  3363. C5_EMISSAO: $('#C5_EMISSAO').val(),
  3364. C5_NROPOR: $('#C5_NROPOR').val(), //consulta
  3365. C5_TABELA: $('#C5_TABELA').val(),
  3366. C5_YNUMORC: $('#C5_YNUMORC').val(), //consulta
  3367. C5_SIBAP: $('#C5_SIBAP').val(),
  3368. C5_ENDOPC: $('#C5_ENDOPC').val(),
  3369. C5_GRPTRIB: $('#C5_GRPTRIB').val(), //consulta
  3370. C5_CEPOPC: $("#C5_CEPOPC").val(),
  3371. C5_RUAOPC: $("#C5_RUAOPC").val(),
  3372. C5_NUMOPC: $("#C5_NUMOPC").val(),
  3373. C5_BAIROPC: $("#C5_BAIROPC").val(),
  3374. C5_MUNOPC: $("#C5_MUNOPC").val(),
  3375. C5_UFOPC: $("#C5_UFOPC").val(),
  3376. C5_REFOPC: $("#C5_REFOPC").val(),
  3377. C5_AMARRPV: $('#C5_AMARRPV').val(), //consulta
  3378. C5_COMISTR: $('#C5_COMISTR').val(), //consulta
  3379. C5_JUS: $('#C5_JUS').val(), //consulta
  3380. C5_MENNOTA: $('#C5_MENNOTA').val(),
  3381. C5_MENNOT1: $('#C5_MENNOT1').val(),
  3382. C5_MENNOT2: $('#C5_MENNOT2').val(),
  3383. C5_MENNOT3: $('#C5_MENNOT3').val(),
  3384. C5_DESCFAT: $('#C5_DESCFAT').val(),
  3385. C5_YMCPER: $('#C5_YMCPER').val(), //consulta
  3386. C5_UFDEST: $('#UF_ENTREGA').val(),
  3387. PROXIMO: $('#PROXIMO').val(),
  3388. OPCAO: $('#OPCAO').val(),
  3389. aItens: ITENS
  3390. };
  3391. if($("#OPCAO").val() == "3"){
  3392. msg = "O Pedido foi incluído com sucesso.";
  3393. titulo = "Inclusão de Pedido";
  3394. operacao = "incluir";
  3395. }
  3396. if($("#OPCAO").val() == "4"){
  3397. msg = "O Pedido foi alterado com sucesso.";
  3398. titulo = "Alteração de Pedido";
  3399. operacao = "alterar";
  3400. }
  3401. if($("#OPCAO").val() == "5"){
  3402. msg = "O Pedido foi excluído com sucesso.";
  3403. titulo = "Exclusão de Pedido";
  3404. operacao = "excluir";
  3405. }
  3406. $.ajax({
  3407. type: "POST",
  3408. url: "U_SlvPed.apw?PR=<%=cLCodLogin%>",
  3409. async: false,
  3410. data: objDados
  3411. }).fail(function(){
  3412. bootbox.alert({
  3413. title: titulo,
  3414. message: "Não foi possível "+operacao+" o Pedido.",
  3415. backdrop: true,
  3416. callback: function (result) {
  3417. btnSlv.removeAttr('disabled');
  3418. dialogSlv.modal('hide');
  3419. }
  3420. });
  3421. }).done(function(strXml) {
  3422. if (strXml.indexOf('<META HTTP-EQUIV') >= 0 ) {
  3423. $("html").html(strXml);
  3424. return;
  3425. }
  3426. // if (strXml == 'erro'||strXml == ''||strXml.toUpperCase().indexOf("EXPIRES") != -1||strXml.toUpperCase().indexOf("INVALID") != -1){
  3427. if (strXml == 'erro'||strXml == ''||strXml.toUpperCase().indexOf("INVALID") != -1){
  3428. if (strXml == ''){
  3429. bootbox.alert({
  3430. title: titulo,
  3431. message: "Aguarde o prazo de 3 minutos para "+operacao+" um novo Pedido.",
  3432. backdrop: true,
  3433. callback: function (result) {
  3434. btnSlv.removeAttr('disabled');
  3435. dialogSlv.modal('hide');
  3436. }
  3437. });
  3438. }else{
  3439. bootbox.alert({
  3440. title: titulo,
  3441. message: "Falha ao "+operacao+" o Pedido.",
  3442. backdrop: true,
  3443. callback: function (result) {
  3444. btnSlv.removeAttr('disabled');
  3445. dialogSlv.modal('hide');
  3446. }
  3447. });
  3448. }
  3449. }
  3450. else {
  3451. if($("#OPCAO").val() == "3"){
  3452. numorc = " Foi gerado o Pedido nº "+strXml.split('<br>')[0] +"."
  3453. }
  3454. bootbox.alert({
  3455. title: titulo,
  3456. message: msg+numorc,
  3457. backdrop: true,
  3458. callback: function (result) {
  3459. document.location.href = "U_Pedidos.apw?PR=<%=cLCodLogin%>";
  3460. dialogSlv.modal('hide');
  3461. }
  3462. });
  3463. }
  3464. });
  3465. //};
  3466. }
  3467. $('#btExcluir').click(function() {
  3468. var lRet = true
  3469. var i = 0;
  3470. var lGrid = true;
  3471. var cCodProd;
  3472. var btnSlv = $(this);
  3473. //Desabilita o botao
  3474. $('#btExcluir').attr({ 'disabled': 'disabled' });
  3475. objDados = {
  3476. C5_CLIENTE: formataCli($('#C5_CLIENTE').val()),
  3477. C5_NUM: $('#C5_NUM').val()
  3478. };
  3479. $.ajax({
  3480. type: "POST",
  3481. url: "U_ExcOrc.apw?PR=<%=cLCodLogin%>",
  3482. async: false,
  3483. data: objDados
  3484. }).fail(function(){
  3485. bootbox.alert({
  3486. title: "Exclusão de Pedido",
  3487. message: "Não foi possível excluir o Pedido.",
  3488. backdrop: true,
  3489. callback: function (result) {
  3490. btnSlv.removeAttr('disabled');
  3491. }
  3492. });
  3493. }).done(function(strXml) {
  3494. if (strXml.indexOf('<META HTTP-EQUIV') >= 0 ) {
  3495. $("html").html(strXml);
  3496. return;
  3497. }
  3498. bootbox.alert({
  3499. title: "Exclusão de Pedido",
  3500. message: "O Pedido "+$('#C5_NUM').val()+" foi excluído com sucesso.",
  3501. backdrop: true,
  3502. callback: function (result) {
  3503. document.location.href = "U_Pedidos.apw?PR=<%=cLCodLogin%>";
  3504. }
  3505. });
  3506. });
  3507. })
  3508. </script>
  3509. </body>
  3510. </html>