Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.order.component.js 837KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821
  1. var Bizgaze;
  2. (function (Bizgaze) {
  3. let Apps;
  4. (function (Apps) {
  5. let Transact;
  6. (function (Transact) {
  7. let Infos;
  8. (function (Infos) {
  9. class OrderItem {
  10. static Instance() {
  11. if (this.instance === undefined) {
  12. this.instance = new OrderItem();
  13. }
  14. return this.instance;
  15. }
  16. }
  17. Infos.OrderItem = OrderItem;
  18. class FoCItem {
  19. }
  20. Infos.FoCItem = FoCItem;
  21. class ValidOrderFoCItem {
  22. }
  23. Infos.ValidOrderFoCItem = ValidOrderFoCItem;
  24. class AppliedOffer {
  25. }
  26. Infos.AppliedOffer = AppliedOffer;
  27. class OrderTotals {
  28. }
  29. Infos.OrderTotals = OrderTotals;
  30. class UOMSchemaDetails {
  31. }
  32. Infos.UOMSchemaDetails = UOMSchemaDetails;
  33. class POSOrderItem {
  34. static Instance() {
  35. if (this.instance === undefined) {
  36. this.instance = new OrderItem();
  37. }
  38. return this.instance;
  39. }
  40. }
  41. Infos.POSOrderItem = POSOrderItem;
  42. class Cart_Item {
  43. static Instance() {
  44. if (this.instance === undefined) {
  45. this.instance = new Cart_Item();
  46. }
  47. return this.instance;
  48. }
  49. }
  50. Infos.Cart_Item = Cart_Item;
  51. class ValidFoCItem {
  52. }
  53. Infos.ValidFoCItem = ValidFoCItem;
  54. class RawMaterial {
  55. }
  56. Infos.RawMaterial = RawMaterial;
  57. class Operation {
  58. }
  59. Infos.Operation = Operation;
  60. })(Infos = Transact.Infos || (Transact.Infos = {}));
  61. })(Transact = Apps.Transact || (Apps.Transact = {}));
  62. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  63. })(Bizgaze || (Bizgaze = {}));
  64. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  65. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  66. return new (P || (P = Promise))(function (resolve, reject) {
  67. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  68. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  69. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  70. step((generator = generator.apply(thisArg, _arguments || [])).next());
  71. });
  72. };
  73. var Bizgaze;
  74. (function (Bizgaze) {
  75. let Apps;
  76. (function (Apps) {
  77. let Transact;
  78. (function (Transact) {
  79. let Controls;
  80. (function (Controls) {
  81. class OrderItems extends Unibase.Platform.Core.BaseComponent {
  82. constructor() {
  83. super(...arguments);
  84. this._order = Bizgaze.Apps.Transact.Controls.Order.Instance();
  85. this.g_ValidFocItems = [];
  86. this.g_SelectedItems = [];
  87. this.g_AppliedOffers = [];
  88. this.g_LoadedItems = [];
  89. this.g_UOMs = [];
  90. this.g_PurPlanData = [];
  91. this.g_ItemsUnitPrice_New = [];
  92. this.g_CartItems_New = [];
  93. this.g_SC_PC_CartItems = [];
  94. this.g_AppliedTaxGroups = [];
  95. this.g_PageIndex = 0;
  96. this.g_PriceTypeId = 1;
  97. this.g_IsEnablePieces = false;
  98. this.g_IsEnablePacks = false;
  99. this.g_IsEnablePiecePrice = false;
  100. this.g_IsEnableCompositePrice = false;
  101. this.g_IsEnableCompositePiecePrice = false;
  102. this.g_BodyWidth = $('body').width();
  103. this.g_IsExcise = false;
  104. this.g_PacksFocus = true;
  105. this.g_PiecesFocus = false;
  106. this.g_OfferApplyDate = new Date();
  107. this.g_FromWidget = false;
  108. this.g_FromWidgetEditOrderItemId = 0;
  109. this.g_FromContinueShopping = false;
  110. this.g_IsFilterApplied = false;
  111. this.g_TagArray = [];
  112. this.g_ContainerId = "";
  113. this.g_VisibleContainerId = "";
  114. this.Modified_Discount = 0;
  115. }
  116. init(formpropertyid, prop, callback) {
  117. let instance = this;
  118. instance.fileCacheHelper.loadJsFile("apps/transact/enums/enum.js", function () {
  119. instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
  120. instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
  121. });
  122. }
  123. loadControl(containerid, prop) {
  124. let instance = this;
  125. instance.g_ContainerId = containerid;
  126. instance.g_VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  127. instance._order.g_OrderTypeId = Number($("#" + instance.g_VisibleContainerId).find(".hdn_ordertypeid").val());
  128. let html = '<div class="w-100">' +
  129. '<input type = "hidden" id = "hdn_customcontrol" class="value-control" value = "Bizgaze.Apps.Transact.Controls.OrderItems.Instance().getOrderItems();"' +
  130. '<div class="floating-label-form-group div_SearchItem">' +
  131. '<div class="input-group">' +
  132. '<span class="input-group-prepend"></span>' +
  133. '<input type="search" id="txt_SearchItem" class="form-control floating-label-control pl-0" data-isdynamic="false" placeholder="Search Items" data-placeholder="Item Name (or) SKU" data-label="Search Items" autocomplete="on" />' + '<a href="javascript:;" id="crpnrd_btn_OpenScanner" class="input-group-append helo" ><span class="input-group-text" > <i class="fa fa-qrcode" > </i></span ></a>' +
  134. `<a href = "javascript:;" class="search-clear-items d-none" id = "` + containerid + `" onclick="Bizgaze.Apps.Transact.Controls.OrderItems.Instance().clearItemSearch()"> <i class="zmdi zmdi-close"></i></a> ` +
  135. '<span class="input-group-prepend input-group-btn p-0">';
  136. instance.fileCacheHelper.loadJsFile("apps/transact/enums/enum.js", function () {
  137. if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  138. html += '<select id="ItemLoadType" class="bg-transparent rounded-4 px-2 font-12"><option value="1">All</option><option value="2">Filter</option></select>';
  139. }
  140. else {
  141. html += '<select id="ItemLoadType" class="bg-transparent rounded-4 px-2 font-12"><option value="1">All</option><option value="2">Offers</option><option value="3">Filter</option></select>';
  142. }
  143. html += '</span>' +
  144. '</div>' +
  145. '</div>' +
  146. '</div>' +
  147. '<br/> <div class="InventorySettings"> </div>';
  148. $("#" + instance.g_VisibleContainerId).find("#" + containerid).html(html);
  149. instance.ItemsQrScan();
  150. });
  151. $("#" + instance.g_VisibleContainerId).find("#ItemLoadType").unbind().click(function () {
  152. $("#" + instance.g_VisibleContainerId).find(".div_SearchItem").removeClass("floating-label-form-group-with-value");
  153. });
  154. $("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").focusout(function () {
  155. if ($("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val() == "") {
  156. $("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").attr("placeholder", "Search Items");
  157. }
  158. });
  159. }
  160. ItemsQrScan() {
  161. $("#crpnrd_btn_OpenScanner").addClass("hidden");
  162. if (isMobileApp()) {
  163. $("#crpnrd_btn_OpenScanner").removeClass("hidden");
  164. $("#crpnrd_btn_OpenScanner").click(function () {
  165. Unibase.Platform.Helpers.MobileHelper.Instance().openQrScanner("Bizgaze.Apps.Transact.Controls.OrderItems.Instance().readScanner", "txt_SearchItem");
  166. });
  167. }
  168. else {
  169. $("#crpnrd_btn_OpenScanner").addClass("hidden");
  170. }
  171. }
  172. loadControlSettings(controlsettingjson, formpropertyid) {
  173. return null;
  174. }
  175. loadPropertySettings(propertysettings, formpropertyid) {
  176. return null;
  177. }
  178. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  179. return null;
  180. }
  181. loadItems(SearchItem, UpdateAvailability = false) {
  182. let instance = this;
  183. $("#" + instance.g_VisibleContainerId).find('.section_Items').removeClass('hidden');
  184. let OrganizationId = instance._order.g_OrganizationId;
  185. let LoBId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_lobid").val();
  186. let ShipTo = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_shippingaddressid").val();
  187. if (ShipTo == null) {
  188. ShipTo = 0;
  189. }
  190. let BranchId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billfromaddressid").val();
  191. if (SearchItem == "Offers" || SearchItem == "All Items" || SearchItem == "Filter" || SearchItem == "Eligible Items") { }
  192. else
  193. SearchItem = (encodeURIComponent(encodeURIComponent(SearchItem).replace('*', '%2A').replace('.', '%2E'))).replace(/\%/g, '!');
  194. if (!instance._order.g_IsPurchasePlanning) {
  195. if (SearchItem == undefined || SearchItem == '') {
  196. SearchItem = ' ';
  197. }
  198. if (SearchItem == "Offers") {
  199. instance._order.g_LoadOffersOnly = true;
  200. SearchItem = '';
  201. if (instance.g_IsFilterApplied) {
  202. instance.g_IsFilterApplied = false;
  203. instance.g_FilteredTags = '';
  204. instance.g_TagArray = [];
  205. Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_Tags = "";
  206. }
  207. }
  208. else if (SearchItem == "All Items") {
  209. instance._order.g_LoadOffersOnly = false;
  210. instance._order.g_LoadEligibleItemsOnly = false;
  211. instance.g_FilteredTags = '';
  212. instance.g_TagArray = [];
  213. Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_Tags = "";
  214. SearchItem = "";
  215. }
  216. else if (SearchItem == "Filter") {
  217. instance._order.g_LoadOffersOnly = false;
  218. }
  219. else if (SearchItem == "Eligible Items") {
  220. instance._order.g_LoadEligibleItemsOnly = true;
  221. SearchItem = "";
  222. }
  223. let PriceCodeId = instance._order.g_PriceCodeId;
  224. let ContactId = OrganizationId;
  225. if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  226. instance.g_WarehouseId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_shipfromaddressid").val();
  227. }
  228. else if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Purchase || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim) {
  229. instance.g_WarehouseId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_shippingaddressid").val();
  230. }
  231. let varianturl;
  232. if (SearchItem.replace(" ", "") == "") {
  233. SearchItem = null;
  234. }
  235. if (Number(LoBId) == 0) {
  236. $("#" + instance.g_VisibleContainerId).find(".InventorySettings").empty();
  237. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").html('<li id="0" class="cartitem list-group-item col-xs-12 hidden clear no-border"></li> <li class="list-group-item col-xs-12 no-border EmptyCartLi"><strong>Your Shopping Cart is empty.</strong></li>');
  238. }
  239. else {
  240. instance.fileCacheHelper.loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
  241. let ItemIds = "0";
  242. let Rows = 10;
  243. if (instance._order.g_IsSC_to_PC) {
  244. ItemIds = "";
  245. instance.g_CartItems_New.forEach(x => {
  246. ItemIds += x.ItemId + ",";
  247. });
  248. ItemIds = ItemIds.replace(/,\s*$/, "");
  249. Rows = 0;
  250. $("#" + instance.g_VisibleContainerId).find('.section_Items').addClass('hidden');
  251. }
  252. let postdata = {
  253. PriceCodeId: Number(PriceCodeId),
  254. ContactId: ContactId,
  255. ShippingAddressId: Number(ShipTo),
  256. BranchId: Number(BranchId),
  257. WareHouseId: Number(instance.g_WarehouseId),
  258. LobId: Number(LoBId),
  259. OrderType: instance._order.g_OrderTypeId,
  260. OfferOnly: instance._order.g_LoadOffersOnly,
  261. IsExcise: instance.g_IsExcise,
  262. SearchTerm: SearchItem,
  263. Page: instance.g_PageIndex,
  264. IsCompositePrice: instance.g_IsEnableCompositePrice,
  265. IsPiecePrice: instance.g_IsEnablePiecePrice,
  266. IsCompositePiecePrice: instance.g_IsEnableCompositePiecePrice,
  267. Rows: Rows,
  268. ItemId: ItemIds,
  269. CountryId: instance._order.g_CountryId,
  270. ItemGroupId: 0,
  271. Tags: Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_Tags,
  272. IsPoints: instance._order.g_IsPointsOrder,
  273. Points: instance._order.g_LoyaltyPoints,
  274. IsEligibleItemsOnly: instance._order.g_LoadEligibleItemsOnly
  275. };
  276. let cntId = instance._order.g_OrganizationId;
  277. if (cntId == 0)
  278. cntId = instance._order.g_OrgContactId;
  279. if ($("#" + instance.g_VisibleContainerId).find("#ItemLoadType option:selected").text() != "Filter" || (Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_Tags.length == 0 && $("#" + instance.g_VisibleContainerId).find("#ItemLoadType option:selected").text() == "Filter")) {
  280. if (Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_Tags.length == 0 && $("#" + instance.g_VisibleContainerId).find("#ItemLoadType option:selected").text() == "Filter") {
  281. instance._order.g_LoadOffersOnly = false;
  282. }
  283. }
  284. varianturl = Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItemsForOrder(postdata);
  285. instance.navigationHelper.showLoading();
  286. varianturl.then(function (response) {
  287. instance.navigationHelper.hideLoading();
  288. if (UpdateAvailability) {
  289. instance.updateItemsAvailability(response.result);
  290. }
  291. else if (response.result.length > 0) {
  292. instance.itemPagination(response);
  293. if (!instance._order.g_IsPurchasePlanning) {
  294. $("#" + instance.g_VisibleContainerId).find("#btn_CheckOutOrder").removeClass("hidden");
  295. }
  296. if (instance.g_CartItems_New.length == 0) {
  297. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").html('<li id="0" class="cartitem list-group-item col-xs-12 hidden clear no-border"></li> <li class="list-group-item col-xs-12 no-border EmptyCartLi"><strong>Your Shopping Cart is empty.</strong></li>');
  298. }
  299. instance.navigationHelper.hideLoading();
  300. }
  301. else {
  302. $("#" + instance.g_VisibleContainerId).find(".div_titledetails").addClass("hidden");
  303. if (instance._order.g_LoadOffersOnly) {
  304. $("#" + instance.g_VisibleContainerId).find("#div_ItemList").html('<ul class="variant-list list-group" style="margin:0px -21px" id="Items-list"><li class="variant-item"><div class="text-center">Offer Items not found.</div></li></ul>');
  305. }
  306. else if (instance._order.g_LoadEligibleItemsOnly) {
  307. $("#" + instance.g_VisibleContainerId).find("#div_ItemList").html('<ul class="variant-list list-group" style="margin:0px -21px" id="Items-list"><li class="variant-item"><div class="text-center">Eligible Items not found.</div></li></ul>');
  308. }
  309. else {
  310. if (instance._order.g_CreateItem == 1 || instance._order.g_IsAdmin == 1) {
  311. $("#" + instance.g_VisibleContainerId).find("#div_ItemList").html('<ul class="variant-list list-group" style="margin:0px -21px" id="Items-list"><li class="variant-item"> <div class="text-center">Items not found.</div><br><div class="text-center"><button id="btn_AddNewItem" class="btn btn-primary">Create New Item</button></li></ul>');
  312. }
  313. else {
  314. $("#" + instance.g_VisibleContainerId).find("#div_ItemList").html('<ul class="variant-list list-group" style="margin:0px -21px" id="Items-list"><li class="variant-item"><div class="text-center">Items not found.</div></li></ul>');
  315. }
  316. }
  317. if (instance.g_CartItems_New.length == 0 && instance._order.g_IsFromPurchaseIndent) {
  318. let text = "Your Shopping Cart is empty.";
  319. if (instance._order.g_IsFromPurchaseIndent) {
  320. text = "No Pending Purchase Indent Items.";
  321. }
  322. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").html('<li id="0" class="cartitem list-group-item col-xs-12 hidden clear no-border"></li> <li class="list-group-item col-xs-12 no-border EmptyCartLi"><strong>' + text + '</strong></li>');
  323. }
  324. $("#btn_AddNewItem").click(function () {
  325. Bizgaze.Apps.Transact.Controls.OrderItems.Instance().getItemForm();
  326. });
  327. }
  328. });
  329. });
  330. }
  331. }
  332. }
  333. getItemForm() {
  334. let instance = Bizgaze.Apps.Transact.Controls.OrderItems.Instance();
  335. instance.fileCacheHelper.loadJsFiles(['platform/forms/managers/formmanager.js', 'platform/apps/managers/appmanager.js'], function () {
  336. var FormUniqueId = 'Bizgaze_Extension_Transact_Items_App_Items_CreateForm';
  337. Unibase.Platform.Forms.Managers.FormManager.Instance().getFormbyUniqueId(FormUniqueId).then(function (response) {
  338. var successCallBack = {
  339. CallBack: function (ItemId) {
  340. instance.bindNewAddedItem(ItemId);
  341. },
  342. Parameters: null,
  343. };
  344. var onLoadAddItem = {
  345. CallBack: function (ItemId) {
  346. let VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  347. let Parameters = [
  348. { ColumnName: 'lobid', Value: instance._order.g_LobId },
  349. ];
  350. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($("#" + VisibleContainerId).find(".txtAutoComplete_productid"), Parameters);
  351. },
  352. Parameters: null,
  353. };
  354. var formviewerObj = {
  355. FormId: response.result.FormId,
  356. AppConfigurationId: 0,
  357. Pk_Value: 0,
  358. PortletWidgetId: 0,
  359. OnSuccess: successCallBack,
  360. OnFail: null,
  361. OnLoad: onLoadAddItem,
  362. };
  363. Unibase.Platform.Forms.Components.FormViewer.Instance().init(formviewerObj);
  364. instance.navigationHelper.hideLoading();
  365. });
  366. });
  367. }
  368. bindNewAddedItem(ItemId) {
  369. let instance = this;
  370. let LoBId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_lobid").val();
  371. let ShipTo = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_shippingaddressid").val();
  372. if (ShipTo == null) {
  373. ShipTo = 0;
  374. }
  375. let BranchId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billfromaddressid").val();
  376. let postdata = {
  377. PriceCodeId: Number(instance._order.g_PriceCodeId),
  378. ContactId: instance._order.g_OrganizationId,
  379. ShippingAddressId: Number(ShipTo),
  380. BranchId: Number(BranchId),
  381. WareHouseId: Number(instance.g_WarehouseId),
  382. LobId: Number(LoBId),
  383. OrderType: instance._order.g_OrderTypeId,
  384. OfferOnly: false,
  385. IsExcise: instance.g_IsExcise,
  386. SearchTerm: "",
  387. Page: 0,
  388. IsCompositePrice: instance.g_IsEnableCompositePrice,
  389. IsPiecePrice: instance.g_IsEnablePiecePrice,
  390. IsCompositePiecePrice: instance.g_IsEnableCompositePiecePrice,
  391. Rows: 10,
  392. ItemId: ItemId.toString(),
  393. CountryId: instance._order.g_CountryId,
  394. ItemGroupId: 0,
  395. Tags: "",
  396. IsPoints: instance._order.g_IsPointsOrder,
  397. Points: instance._order.g_LoyaltyPoints,
  398. IsEligibleItemsOnly: instance._order.g_LoadEligibleItemsOnly,
  399. ApplyDate: instance.g_OfferApplyDate
  400. };
  401. Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItemsForOrder(postdata).then(function (res) {
  402. instance.itemPagination(res);
  403. });
  404. }
  405. loadPurchasePlanItems(SearchTerm) {
  406. let instance = this;
  407. let LoadTypeId = Number($("#" + instance.g_VisibleContainerId).find("#ItemLoadType option:selected").val());
  408. SearchTerm = SearchTerm == "" ? null : SearchTerm;
  409. instance.navigationHelper.showLoading();
  410. $("#" + instance.g_VisibleContainerId).find(".divselectall").removeClass('hidden');
  411. let VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  412. $("#" + instance.g_VisibleContainerId).find("#" + VisibleContainerId).find(".Section").addClass("hidden");
  413. $("#" + instance.g_VisibleContainerId).find("#" + VisibleContainerId).find(".section_Items, .section_Calculations").removeClass("hidden");
  414. $("#" + instance.g_VisibleContainerId).find("#" + VisibleContainerId).find("#btn_Checkout").addClass("hidden");
  415. let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters;
  416. let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  417. let EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value);
  418. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getPurchasePlanItems(EstimateId, LoadTypeId, SearchTerm, 0).then(function (response) {
  419. instance.navigationHelper.hideLoading();
  420. if (response.code == "0") {
  421. var data = response.result;
  422. $("#" + instance.g_VisibleContainerId).find(".variant-addeditem").empty();
  423. instance.itemPagination(response);
  424. }
  425. else {
  426. Unibase.Platform.Forms.Components.FormViewer.Instance().showError(response.code);
  427. }
  428. });
  429. }
  430. itemPagination(response) {
  431. let instance = this;
  432. response.result.forEach(x => {
  433. let LoadedItem_Index = instance.g_LoadedItems.findIndex(z => z.ItemId == x.ItemId);
  434. if (LoadedItem_Index == -1) {
  435. instance.g_LoadedItems.push(x);
  436. }
  437. else {
  438. instance.g_LoadedItems[LoadedItem_Index].TaxPercentList = x.TaxPercentList;
  439. }
  440. });
  441. instance.bindItemList(response.result);
  442. if (response.result.length <= 10 && response.result.length != 0) {
  443. $("#" + instance.g_VisibleContainerId).find('#div_OrderItems_pagination').removeClass('hidden');
  444. $("#" + instance.g_VisibleContainerId).find('#ItemsListPagination').removeClass('hidden');
  445. let totalCount = response.result[0].TotalRecords;
  446. if (instance._order.g_IsPurchasePlanning) {
  447. totalCount = response.result.length;
  448. }
  449. let startingValue = 0;
  450. let _count = 0;
  451. let t = (instance.g_PageIndex + 1) * 10;
  452. if (totalCount > 0) {
  453. startingValue = 1;
  454. _count = totalCount;
  455. }
  456. if (totalCount > t)
  457. _count = t;
  458. if (instance.g_PageIndex > 0) {
  459. startingValue += t - 10;
  460. }
  461. let res = startingValue + " - " + _count + " of " + totalCount;
  462. $("#" + instance.g_VisibleContainerId).find('#lblItemTotalRecords').text(res);
  463. $("#" + instance.g_VisibleContainerId).find('.labelSection_ItemsCount').text("Total: " + response.result.length + " Items").addClass("col-sm-12").addClass("text-right").addClass("h5");
  464. let elem = $("#" + instance.g_VisibleContainerId).find('#ItemsListPagination');
  465. elem.pagination(response.result[0].TotalRecords, 10, {
  466. items_per_page: 10,
  467. callback: function (page, component) {
  468. instance.g_PageIndex = page;
  469. instance.loadItems($("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val());
  470. }, current_page: instance.g_PageIndex
  471. });
  472. }
  473. else {
  474. $("#" + instance.g_VisibleContainerId).find('#lblItemTotalRecords').text(response.result.length);
  475. $("#" + instance.g_VisibleContainerId).find('.labelSection_ItemsCount').text("Total: " + response.result.length + " Items").addClass("col-sm-12").addClass("text-right").addClass("h5");
  476. $("#" + instance.g_VisibleContainerId).find("#ItemsListPagination").addClass("hidden");
  477. }
  478. }
  479. bindItemList(items) {
  480. let instance = this;
  481. let LobId = Number($("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_lobid").val());
  482. let BillingAddressId = Number($("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billingaddressid").val());
  483. let BranchId = Number($("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billfromaddressid").val());
  484. $("#" + instance.g_VisibleContainerId).find("#div_ItemList").html('<ul class="variant-list list-group" id="Items-list" style="margin:0px -21px"><li class="variant-item hidden"></li>');
  485. if (items.length == 0) {
  486. if (instance._order.g_LoadOffersOnly) {
  487. $("#" + instance.g_VisibleContainerId).find(".variant-list").html('<li><div class="text-center">Offer Items not found.</div></li></ul>');
  488. }
  489. else if (instance._order.g_LoadEligibleItemsOnly) {
  490. $("#" + instance.g_VisibleContainerId).find(".variant-list").html('<li><div class="text-center">Eligible Items not found.</div></li></ul>');
  491. }
  492. else {
  493. $("#" + instance.g_VisibleContainerId).find(".variant-list").html('<li><div class="text-center">Items not found.</div></li></ul>');
  494. }
  495. $("#" + instance.g_VisibleContainerId).find(".div_titledetails").addClass("hidden");
  496. return false;
  497. }
  498. else
  499. $("#" + instance.g_VisibleContainerId).find(".div_titledetails").removeClass("hidden");
  500. let kpi_totalqty = 0;
  501. let kpi_itemscount = 0;
  502. let kpi_totalamount = 0;
  503. let kpi_totalinwardqty = 0;
  504. let kpi_totalinwardamount = 0;
  505. let kpi_ExtraItems = 0;
  506. let kpi_offeritems = 0;
  507. let lbl_Carton = "ml-95";
  508. let lbl_Pieces = "pl-75";
  509. if (instance.g_BodyWidth > 320 && instance.g_BodyWidth < 400) {
  510. lbl_Carton = "ml-45";
  511. lbl_Pieces = "pl-10";
  512. }
  513. if (instance.g_BodyWidth > 400 && instance.g_BodyWidth < 470) {
  514. lbl_Carton = "ml-55";
  515. lbl_Pieces = "pl-25";
  516. }
  517. if (instance.g_BodyWidth > 1300 && instance.g_BodyWidth <= 1600) {
  518. lbl_Carton = "ml-65";
  519. lbl_Pieces = "pl-55";
  520. }
  521. if (instance._order.g_IsPurchasePlanning) {
  522. let temptext = instance.getItemDesignWithTokens_PurchasePlan();
  523. var templateScript = Handlebars.compile(temptext);
  524. var html = "";
  525. $("#" + instance.g_VisibleContainerId).find(".div_PurchasePlanningFooterValues").remove();
  526. $("#" + instance.g_VisibleContainerId).find("#formFooter").append(`<div class="div_PurchasePlanningFooterValues col-sm-10 row"> <div class="col-sm-6" > <strong class="font-15">Total Suggested Qty: <span id="spn_Total_Suggested_Qty"> 0 </span> </span></div><div class="col-sm-6"> <strong class="font-15">Total Suggested Value: <span id="spn_Total_Suggested_Value"> 0 </span> </span></div></div>`);
  527. let TotalSuggestedQty = 0;
  528. let TotalSuggestedValue = 0;
  529. items.forEach(x => {
  530. let url = '';
  531. let ItemImg = "";
  532. let imgtag = "";
  533. let faimg = "";
  534. let LoadedItemIndex = instance.g_LoadedItems.findIndex(y => y.ItemId == x.ItemId);
  535. if (LoadedItemIndex != -1) {
  536. url = instance.g_LoadedItems[LoadedItemIndex].ImageUrl;
  537. if (url == "" || url == undefined || url == null) {
  538. faimg = "";
  539. imgtag = "hidden";
  540. }
  541. else {
  542. faimg = "hidden";
  543. imgtag = "";
  544. }
  545. }
  546. else {
  547. if (x.ImageUrl == "" || x.ImageUrl == undefined || x.ImageUrl == null) {
  548. faimg = "";
  549. imgtag = "hidden";
  550. }
  551. else {
  552. url = x.ImageUrl;
  553. faimg = "hidden";
  554. imgtag = "";
  555. }
  556. }
  557. let Mod_UnitPrice = 0;
  558. let Items_up = instance.g_ItemsUnitPrice_New.filter(y => y.ItemId == x.ItemId);
  559. if (Items_up.length == 0) {
  560. Mod_UnitPrice = x.ConfirmedUnitPrice;
  561. instance.g_ItemsUnitPrice_New.push({
  562. ItemId: x.ItemId,
  563. UnitPrice: x.UnitPrice,
  564. TaxRateAmount: x.TaxRateAmount
  565. });
  566. }
  567. else {
  568. Mod_UnitPrice = Items_up[0].ConfirmedUnitPrice;
  569. }
  570. let PurchasePlanChecked = "";
  571. if (x.IsConfirmed) {
  572. PurchasePlanChecked = "checked";
  573. }
  574. let OrderQuantity = "";
  575. let multiplevalue = "";
  576. if (x.ConfirmedPacks > 0 && x.ConfirmedQty > 0) {
  577. x.SuggestedPacks = x.ConfirmedPacks;
  578. }
  579. if ((x.SuggestedPacks) != 0 && (x.SuggestedPacks) != null && (x.SuggestedPacks) != undefined) {
  580. let unitprice = Number(Mod_UnitPrice);
  581. let packCount = Number(x.PackCount);
  582. let packSize = Number(x.PackSize);
  583. let baseqty = packCount * packSize * x.SuggestedPacks;
  584. OrderQuantity = " X " + (baseqty);
  585. multiplevalue = " = " + (unitprice * baseqty);
  586. TotalSuggestedQty += baseqty;
  587. TotalSuggestedValue += (unitprice * baseqty);
  588. }
  589. let offerDiscountClass = "";
  590. if (x.IsOfferAvailable && x.IsOfferDiscountApplied && !instance._order.g_IsManageOfferDiscount) {
  591. offerDiscountClass = "readonly";
  592. }
  593. let Discount = 0;
  594. if (x.ConfirmedDiscountValue > 0) {
  595. Discount = x.ConfirmedDiscountValue;
  596. }
  597. if (x.ConfirmedDiscountPercent > 0) {
  598. Discount = x.ConfirmedDiscountPercent;
  599. }
  600. let fltngclass_Cartons = "", fltngclass_Pieces = "", PP_Cartons = "", PP_Pieces = "";
  601. if (x.SuggestedPacks != 0) {
  602. PP_Cartons = x.ConfirmedPacks.toString();
  603. }
  604. let CartItem_Index = -1;
  605. CartItem_Index = instance.g_CartItems_New.findIndex(y => y.ItemId == x.ItemId && y.RefItemIds == "");
  606. let CartItem = instance.g_CartItems_New[CartItem_Index];
  607. if (CartItem != undefined) {
  608. PP_Cartons = CartItem.Packs.toString();
  609. PP_Pieces = CartItem.Pieces.toString();
  610. }
  611. if (PP_Cartons == "0") {
  612. PP_Cartons = "";
  613. }
  614. if (PP_Cartons != "") {
  615. fltngclass_Cartons = "floating-label-form-group-with-value";
  616. }
  617. if (PP_Pieces == "0") {
  618. PP_Pieces = "";
  619. }
  620. if (PP_Pieces != "") {
  621. fltngclass_Pieces = "floating-label-form-group-with-value";
  622. }
  623. x.imgurl = url;
  624. x.faimg = faimg;
  625. x.imgtag = imgtag;
  626. x.ItemImg = ItemImg;
  627. x.OrderQuantity = OrderQuantity;
  628. x.multiplevalue = multiplevalue;
  629. x.Mod_UnitPrice = Mod_UnitPrice;
  630. x.offerDiscountClass = offerDiscountClass;
  631. x.PP_Cartons = PP_Cartons;
  632. x.PP_Pieces = PP_Pieces;
  633. x.fltngclass_Cartons = fltngclass_Cartons;
  634. x.fltngclass_Pieces = fltngclass_Pieces;
  635. x.PurchasePlanChecked = PurchasePlanChecked;
  636. x.Discount = Discount;
  637. x.BranchId = '"' + x.BranchId.toString() + '"';
  638. x.IsDisabledCheckBox = x.SuggestedPacks > 0 ? "" : "disabled";
  639. let ItemId = x.ItemId;
  640. html = templateScript(x);
  641. $("#" + instance.g_VisibleContainerId).find(".variant-item:last").after(html);
  642. let element = $("#" + instance.g_VisibleContainerId).find(".variant-item:last");
  643. if (x.UnitPrice == 0 && instance.roundOff(x.SuggestedPacks, 0) > 0) {
  644. if (element.find(".tax-error").text() == "") {
  645. element.find(".tax-error").text("Unit price is zero").removeClass("text-danger").addClass("text-warning");
  646. }
  647. }
  648. instance.allItemEvents(element);
  649. let SelItem = instance.g_SelectedItems.find(x => x.ItemId == ItemId);
  650. if (SelItem != null) {
  651. let element = $("#" + instance.g_VisibleContainerId).find(".variant-item:last");
  652. instance.updateItemsDesign(element, "BindItemList");
  653. if (SelItem.Packs == 0) {
  654. $("#" + instance.g_VisibleContainerId).find(element).find(".txtOrder_ItemCount").val("");
  655. }
  656. if (SelItem.Pieces == 0) {
  657. $("#" + instance.g_VisibleContainerId).find(element).find(".txtOrder_ItemPieceCount").val("");
  658. }
  659. instance.checkValidations(ItemId, false);
  660. }
  661. else {
  662. if (instance._order.g_IsPurchasePlanning && x.SuggestedPacks > 0) {
  663. }
  664. else {
  665. $("#" + instance.g_VisibleContainerId).find(element).find(".txtOrder_ItemCount").val("");
  666. $("#" + instance.g_VisibleContainerId).find(element).find(".txtOrder_ItemPieceCount").val("");
  667. }
  668. }
  669. });
  670. TotalSuggestedQty = instance.roundOffIgnoreZerosAfterDecimal(TotalSuggestedQty);
  671. TotalSuggestedValue = instance.roundOffIgnoreZerosAfterDecimal(TotalSuggestedValue);
  672. $("#" + instance.g_VisibleContainerId).find("#spn_Total_Suggested_Qty").text(TotalSuggestedQty);
  673. $("#" + instance.g_VisibleContainerId).find("#spn_Total_Suggested_Value").text(TotalSuggestedValue);
  674. if ($("#" + instance.g_VisibleContainerId).find(".chk_PurPlanItem:visible").length != $("#" + instance.g_VisibleContainerId).find(".chk_PurPlanItem:visible:checked").length) {
  675. $("#" + instance.g_VisibleContainerId).find('#chk_AllItems').prop('checked', false);
  676. }
  677. else {
  678. $("#" + instance.g_VisibleContainerId).find('#chk_AllItems').prop('checked', true);
  679. }
  680. instance.navigationHelper.showLoading();
  681. $("#" + instance.g_VisibleContainerId).find(".variant-list").find(".chk_PurPlanItem:checked").each(function () {
  682. let element = $("#" + instance.g_VisibleContainerId).find(this).closest(".variant-item");
  683. if (element.find("#txt_Cartons").val() != 0 && element.find("#txt_Cartons").val() != "") {
  684. instance.updateItemsArray(element, "PurPlan_AllItems", false);
  685. $("#" + instance.g_VisibleContainerId).find(element).find(".chk_PurPlanItem").prop("checked", true);
  686. }
  687. });
  688. instance.navigationHelper.hideLoading();
  689. instance.getPurchasePlanTotals(true, false);
  690. }
  691. else {
  692. for (let i = 0; i < items.length; i++) {
  693. let data;
  694. if (instance._order.g_IsPurchasePlanning) {
  695. data = items[i];
  696. let kpi_suggestedPacks = items[i].SuggestedPacks;
  697. let kpi_inwardPacks = items[i].InwardOrderPacks;
  698. let kpi_packSize = data.PackSize;
  699. let kpi_packCount = data.PackCount;
  700. let kpi_unitprice = data.UnitPrice;
  701. kpi_totalqty += (Number(kpi_suggestedPacks) * Number(kpi_packSize) * Number(kpi_packCount));
  702. kpi_totalamount += (Number(kpi_suggestedPacks) * Number(kpi_unitprice) * Number(kpi_packSize) * Number(kpi_packCount));
  703. if (Number(kpi_suggestedPacks) > 0) {
  704. kpi_itemscount += kpi_suggestedPacks;
  705. }
  706. kpi_totalinwardqty += (Number(kpi_inwardPacks) * Number(kpi_packSize) * Number(kpi_packCount));
  707. kpi_totalinwardamount += (Number(kpi_inwardPacks) * Number(kpi_unitprice) * Number(kpi_packSize) * Number(kpi_packCount));
  708. }
  709. else {
  710. data = items[i];
  711. }
  712. let ItemId = data.ItemId;
  713. let html = "";
  714. if (instance._order.g_IsPurchasePlanning) {
  715. if ((items[i].SuggestedPacks) != 0 && (items[i].SuggestedPacks) != null && (items[i].SuggestedPacks) != undefined) {
  716. }
  717. else if (data.IsOfferAvailable)
  718. kpi_offeritems++;
  719. else
  720. kpi_ExtraItems++;
  721. html = instance.getItemDesign(items[i]);
  722. }
  723. else {
  724. html = instance.getItemDesign(data);
  725. }
  726. $("#" + instance.g_VisibleContainerId).find(".variant-item:last").after(html);
  727. let element = $("#" + instance.g_VisibleContainerId).find(".variant-item:last");
  728. if (instance._order.g_IsPurchasePlanning) {
  729. if (data.UnitPrice == 0 && instance.roundOff(items[i].SuggestedPacks, 0) > 0) {
  730. if (element.find(".tax-error").text() == "") {
  731. element.find(".tax-error").text("Unit price is zero").removeClass("text-danger").addClass("text-warning");
  732. }
  733. }
  734. }
  735. instance.allItemEvents(element);
  736. let SelItem = instance.g_SelectedItems.find(x => x.ItemId == ItemId);
  737. if (SelItem != null) {
  738. let element = $("#" + instance.g_VisibleContainerId).find(".variant-item:last");
  739. instance.updateItemsDesign(element, "BindItemList");
  740. if (SelItem.Packs == 0) {
  741. $("#" + instance.g_VisibleContainerId).find(element).find(".txtOrder_ItemCount").val("");
  742. }
  743. if (SelItem.Pieces == 0) {
  744. $("#" + instance.g_VisibleContainerId).find(element).find(".txtOrder_ItemPieceCount").val("");
  745. }
  746. instance.checkValidations(ItemId, false);
  747. }
  748. else {
  749. if (instance._order.g_IsPurchasePlanning && items[i].SuggestedPacks > 0) {
  750. }
  751. else {
  752. $("#" + instance.g_VisibleContainerId).find(element).find(".txtOrder_ItemCount").val("");
  753. $("#" + instance.g_VisibleContainerId).find(element).find(".txtOrder_ItemPieceCount").val("");
  754. }
  755. }
  756. }
  757. }
  758. let pageHtml = "";
  759. pageHtml = '<div class="row mt-15 col-sm-12"> ' +
  760. '<div class="col-sm-3">' +
  761. '<span class="text-dark ml-30">Total : <span id="lblItemTotalRecords" class="">0</span></span>' +
  762. '</div>' +
  763. '<div class="col-sm-9 hidden" id="div_OrderItems_pagination">' +
  764. '<div id="ItemsListPagination" class="pagination custom-pagination pagination-rounded pull-right mr-20"></div>' +
  765. '</div>' +
  766. '</div>';
  767. $("#" + instance.g_VisibleContainerId).find(".variant-item:last").after(pageHtml);
  768. if (instance._order.g_IsPurchasePlanning) {
  769. $("#" + instance.g_VisibleContainerId).find("#span_SuggPurchaseOrderValue").text(kpi_totalamount);
  770. $("#" + instance.g_VisibleContainerId).find("#span_SuggPurchaseOrderVolume").text(kpi_itemscount);
  771. $("#" + instance.g_VisibleContainerId).find("#span_PurchaseOrderVolume").text(kpi_totalinwardqty);
  772. $("#" + instance.g_VisibleContainerId).find("#span_PurchaseOrderValue").text(kpi_totalinwardamount);
  773. $("#" + instance.g_VisibleContainerId).find("#span_OfferItems").text(kpi_offeritems);
  774. $("#" + instance.g_VisibleContainerId).find("#span_ExtraItems").text(kpi_ExtraItems);
  775. }
  776. if (instance._order.g_IsSC_to_PC) {
  777. for (let i = 0; i < instance.g_CartItems_New.length; i++) {
  778. let Itm = instance.g_CartItems_New[i];
  779. let elem = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + Itm.ItemId);
  780. if (elem != undefined && elem.length > 0) {
  781. let row = instance.g_LoadedItems.find(x => x.ItemId == Itm.ItemId);
  782. if (row != undefined && row != null) {
  783. $("#" + instance.g_VisibleContainerId).find(elem).find("#txt_editItemPrice").val(row.UnitPrice);
  784. }
  785. if (instance._order.g_InventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  786. $("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemCount").val(Itm.Quantity);
  787. }
  788. else {
  789. let onlyPacks = parseInt((Number(Itm.Quantity) / Number(row.PackCount * row.PackSize)).toString());
  790. let remainingQty = Itm.Quantity - (onlyPacks * row.PackCount * row.PackSize);
  791. let onlyPieces = remainingQty / row.PackSize;
  792. Itm.Packs = Number(onlyPacks);
  793. Itm.Pieces = Number(instance.roundOff(onlyPieces));
  794. $("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemCount").val(Itm.Packs);
  795. $("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemPieceCount").val(Itm.Pieces);
  796. }
  797. $("#" + instance.g_VisibleContainerId).find(elem).find(".btnOrder_DiscType").val(Itm.DiscountType);
  798. if (Itm.DiscountPercent > 0) {
  799. $("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").val(Itm.DiscountPercent);
  800. }
  801. else {
  802. $("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").val(Itm.DiscountValue);
  803. }
  804. instance.updateItemsArray(elem, "Bind_SC_PC_CartItems", false, 0);
  805. }
  806. let cart_elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + Itm.ItemId);
  807. if (cart_elem.length == 0) {
  808. instance.addCartItem(Itm.ItemId);
  809. }
  810. cart_elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + Itm.ItemId);
  811. if (cart_elem != undefined && cart_elem.length > 0) {
  812. let row = instance.g_LoadedItems.find(x => x.ItemId == Itm.ItemId);
  813. if (row != undefined && row != null) {
  814. $("#" + instance.g_VisibleContainerId).find(cart_elem).find("#txt_editItemPrice").val(row.UnitPrice);
  815. }
  816. if (instance._order.g_InventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  817. $("#" + instance.g_VisibleContainerId).find(cart_elem).find(".txtOrder_ItemCount").val(Itm.Quantity);
  818. }
  819. else {
  820. $("#" + instance.g_VisibleContainerId).find(cart_elem).find(".txtOrder_ItemCount").val(Itm.Packs);
  821. $("#" + instance.g_VisibleContainerId).find(cart_elem).find(".txtOrder_ItemPieceCount").val(Itm.Pieces);
  822. }
  823. $("#" + instance.g_VisibleContainerId).find(cart_elem).find(".btnOrder_DiscType").val(Itm.DiscountType);
  824. if (Itm.DiscountPercent > 0) {
  825. $("#" + instance.g_VisibleContainerId).find(cart_elem).find("#Ord_txtdiscount").val(Itm.DiscountPercent);
  826. }
  827. else {
  828. $("#" + instance.g_VisibleContainerId).find(cart_elem).find("#Ord_txtdiscount").val(Itm.DiscountValue);
  829. }
  830. instance.updateItemsArray(cart_elem, "Bind_SC_PC_CartItems", false);
  831. }
  832. }
  833. }
  834. }
  835. updateItemsArray(elem, event, FromWidget = false, Qty = 0, Pcs = 0) {
  836. let instance = this;
  837. let OrderItemId = 0;
  838. let RefOrderItemId = 0;
  839. let SelectedUnitId = 1;
  840. let SelectedUnitName = "";
  841. let DefaultSize = 0;
  842. if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length > 0 && !instance._order.g_IsSC_to_PC && !instance._order.g_IsPurchasePlanning && !instance._order.g_IsFromPurchaseIndent) {
  843. FromWidget = true;
  844. }
  845. let DiscountPercent = 0, DiscountValue = 0, DiscountAmount = 0, AfterDiscountValue = 0, BaseQty = 0, TaxGroupId = 0, TaxGroupName = "", TaxAmount = 0, StrTaxPercents = "", TaxRateAmount = 0, Amount = 0, IsCheckPendingItems = false, IsLeverageError = false, IsTaxError = false;
  846. let IsCalculateTax = instance._order.g_IsCalculateTax;
  847. let ItemIndex = instance.g_CartItems_New.length + 1;
  848. let optoutAmount = 0;
  849. let ItemId = Number($("#" + instance.g_VisibleContainerId).find(elem).find(".hfOrder_ItemId").val());
  850. let Packs = isNaN(Number($("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemCount").val())) ? 0 : Number($("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemCount").val());
  851. let Pieces = isNaN(Number($("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemPieceCount").val())) ? 0 : Number($("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemPieceCount").val());
  852. if (Pieces == 0 && Pcs > 0) {
  853. Pieces = Pcs;
  854. }
  855. let UnitPrice = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#txt_editItemPrice").val());
  856. let UnitPriceWithOutTax = UnitPrice;
  857. let DiscountType = Number($("#" + instance.g_VisibleContainerId).find(elem).find(".btnOrder_DiscType").val());
  858. let IsExchangeDC = $("#" + instance.g_VisibleContainerId).find(elem).find(".chkItem_ExchangeDC").prop("checked");
  859. if (IsExchangeDC == undefined) {
  860. IsExchangeDC = false;
  861. }
  862. let IsAfterTax = $("#" + instance.g_VisibleContainerId).find(elem).find(".divAfterTax").is(':checked');
  863. if (DiscountType == 1) {
  864. DiscountPercent = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").val());
  865. DiscountAmount = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#txt_editItemPrice").val()) * Number(DiscountPercent / 100);
  866. AfterDiscountValue = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#txt_editItemPrice").val()) - Number(DiscountAmount);
  867. }
  868. else if (DiscountType == 2) {
  869. DiscountValue = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").val());
  870. DiscountAmount = DiscountValue;
  871. AfterDiscountValue = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#txt_editItemPrice").val()) - DiscountValue;
  872. }
  873. let LoadedItems_Index = instance.g_LoadedItems.findIndex(x => x.ItemId == ItemId);
  874. let SelectedItems_Index = -1;
  875. if (instance.g_SelectedItems != undefined) {
  876. SelectedItems_Index = instance.g_SelectedItems.findIndex(x => x.ItemId == ItemId && x.RefItemIds == "");
  877. }
  878. let CartItems_Index = -1;
  879. if (instance.g_CartItems_New != undefined) {
  880. CartItems_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds == "");
  881. }
  882. let row = instance.g_LoadedItems[LoadedItems_Index];
  883. let PurPlan_Index = instance.g_PurPlanData.findIndex(x => x.ItemId == ItemId);
  884. let PurPlanRow = [];
  885. if (PurPlan_Index != -1) {
  886. PurPlanRow = instance.g_PurPlanData[PurPlan_Index];
  887. }
  888. else {
  889. PurPlanRow = row;
  890. }
  891. let PartNo = row.PartNo;
  892. if (PartNo == undefined || PartNo == "null" || PartNo == null) {
  893. PartNo = "";
  894. }
  895. let Items_up = instance.g_ItemsUnitPrice_New.find(x => x.ItemId == ItemId);
  896. Items_up.UnitPrice = UnitPrice;
  897. if (Items_up.length == 0) {
  898. instance.g_ItemsUnitPrice_New.push({
  899. ItemId: ItemId,
  900. UnitPrice: UnitPrice,
  901. TaxRateAmount: TaxRateAmount
  902. });
  903. }
  904. let Quantity = 0;
  905. let UOMQuantity = 0;
  906. if (instance._order.g_InventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  907. BaseQty = Number(Packs);
  908. Quantity = Packs;
  909. let onlyPacks = parseInt((Number(Quantity) / Number(row.PackCount * row.PackSize)).toString());
  910. let remainingQty = Quantity - (onlyPacks * row.PackCount * row.PackSize);
  911. let onlyPieces = remainingQty / row.PackSize;
  912. Packs = Number(onlyPacks);
  913. Pieces = Number(instance.roundOff(onlyPieces));
  914. }
  915. else {
  916. if (Qty != 0) {
  917. BaseQty = Qty;
  918. Quantity = Qty;
  919. }
  920. else {
  921. BaseQty = Number(row.PackCount) * Number(row.PackSize) * Number(Packs) + (Pieces * row.PackSize);
  922. Quantity = ((row.PackCount * row.PackSize) * Packs) + (Pieces * row.PackSize);
  923. }
  924. }
  925. if (row.IsMultipleUOMs) {
  926. SelectedUnitId = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#ddl_MultipleUOMs_" + ItemId).val());
  927. if (SelectedUnitId != 1 && SelectedUnitId != 0) {
  928. let MultipleUOM = row.MultipleUOMs.find(x => x.SchemaDetailId == SelectedUnitId);
  929. UOMQuantity = instance.roundOff(Quantity * (MultipleUOM.AlternateSize / MultipleUOM.DefaultSize));
  930. BaseQty = UOMQuantity;
  931. DefaultSize = MultipleUOM.DefaultSize;
  932. SelectedUnitName = MultipleUOM.AlternateUnitName;
  933. }
  934. }
  935. if (row.IsManualUOM && instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales) {
  936. SelectedUnitId = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#ddl_ManualUOMs_" + ItemId).val());
  937. if (isNaN(SelectedUnitId)) {
  938. SelectedUnitId = 1;
  939. }
  940. UOMQuantity = Number($("#" + instance.g_VisibleContainerId).find(elem).find("#txt_ManualConversionQty").val());
  941. if (UOMQuantity <= 0 || isNaN(UOMQuantity)) {
  942. UOMQuantity = Packs;
  943. }
  944. BaseQty = UOMQuantity;
  945. SelectedUnitName = $("#ddl_ManualUOMs_" + ItemId + " option:selected").text();
  946. }
  947. Quantity = instance.roundOffIgnoreZerosAfterDecimal(Quantity);
  948. UOMQuantity = instance.roundOffIgnoreZerosAfterDecimal(UOMQuantity);
  949. if (event == "Plus" || event == "Packs" || event == "Pieces") {
  950. IsCheckPendingItems = true;
  951. }
  952. else {
  953. if (Quantity == 0 && !FromWidget) {
  954. IsCheckPendingItems = true;
  955. }
  956. }
  957. if (SelectedItems_Index != -1) {
  958. if (event == "Plus" || event == "Packs" || event == "Pieces" || event == "ApplyOffer") {
  959. IsCheckPendingItems = instance.g_SelectedItems[SelectedItems_Index].IsCheckPendingItems;
  960. let qty = instance.g_SelectedItems[SelectedItems_Index].BaseQty;
  961. if (IsCheckPendingItems && qty > 0 && !FromWidget) {
  962. IsCheckPendingItems = false;
  963. }
  964. }
  965. ItemIndex = instance.g_SelectedItems[SelectedItems_Index].ItemIndex;
  966. OrderItemId = instance.g_SelectedItems[SelectedItems_Index].OrderItemId;
  967. RefOrderItemId = instance.g_SelectedItems[SelectedItems_Index].RefOrderItemId;
  968. $("#" + instance.g_VisibleContainerId).find(elem).find(".tax-error").text("");
  969. $("#" + instance.g_VisibleContainerId).find(elem).find("#LeverageErrorTxt").addClass("hidden");
  970. }
  971. if (instance.g_IsEnableCompositePiecePrice) {
  972. Amount = (UnitPriceWithOutTax * Number(BaseQty)) + Number(row.TaxRate);
  973. if (Number(BaseQty) == 0)
  974. Amount = 0;
  975. UnitPrice = instance.roundOffIgnoreZerosAfterDecimal(row.CompositePiecePrice);
  976. }
  977. else if (instance.g_IsEnableCompositePrice) {
  978. let amnt = Number(UnitPriceWithOutTax) * Number(row.TaxPercentage) / 100;
  979. TaxRateAmount = Number(UnitPriceWithOutTax) + Number(amnt);
  980. Amount = Number(BaseQty) * TaxRateAmount;
  981. UnitPrice = instance.roundOffIgnoreZerosAfterDecimal(row.CompositePrice);
  982. }
  983. else if (instance.g_IsEnablePiecePrice) {
  984. Amount = Number(BaseQty) * UnitPriceWithOutTax;
  985. UnitPrice = instance.roundOffIgnoreZerosAfterDecimal(row.PiecePrice);
  986. }
  987. else {
  988. Amount = Number(BaseQty) * UnitPriceWithOutTax;
  989. }
  990. Items_up.TaxRateAmount = TaxRateAmount;
  991. let AssessableAmount = Number(Amount);
  992. let discVal = Number(DiscountValue) * Number(BaseQty);
  993. let discPercent = Number(DiscountPercent);
  994. let DiscAmount = Number((Amount * discPercent) / 100) + Number(discVal);
  995. let discAmt = DiscAmount + Number(optoutAmount);
  996. AssessableAmount = Number(AssessableAmount) - Number(discAmt);
  997. let AmountWithDiscount = instance.roundOffIgnoreZerosAfterDecimal(Number(Amount) - Number(discAmt));
  998. if (IsCalculateTax) {
  999. if (instance.g_IsEnableCompositePiecePrice || instance.g_IsEnableCompositePrice) {
  1000. if (row.TaxGroupId == 0) {
  1001. IsTaxError = true;
  1002. }
  1003. else {
  1004. TaxGroupId = row.TaxGroupId;
  1005. TaxGroupName = row.TaxGroupName;
  1006. for (let p = 0; p < row.TaxPercentList.length; p++) {
  1007. let percen = row.TaxPercentList[p];
  1008. let tax = AssessableAmount * percen.Percentage / 100;
  1009. TaxAmount += tax;
  1010. }
  1011. StrTaxPercents = row.strTaxPercents;
  1012. instance.getPriceTypeValues(ItemId, Packs, Pieces);
  1013. if (instance.g_IsEnablePiecePrice) {
  1014. UnitPrice = row.PiecePrice;
  1015. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.PiecePrice;
  1016. }
  1017. else if (instance.g_IsEnableCompositePrice) {
  1018. UnitPrice = row.CompositePrice;
  1019. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.CompositePrice;
  1020. }
  1021. else if (instance.g_IsEnableCompositePiecePrice) {
  1022. UnitPrice = row.CompositePiecePrice;
  1023. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.Both;
  1024. }
  1025. else {
  1026. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.None;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. else {
  1032. $("#" + instance.g_VisibleContainerId).find("#TotalTax").addClass("hidden");
  1033. $("#" + instance.g_VisibleContainerId).find(".divCustomProperties_istaxinclusive").addClass("hidden");
  1034. }
  1035. let Description = "";
  1036. if (instance.g_FromWidgetEditOrderItemId > 0) {
  1037. Description = $("#" + instance.g_VisibleContainerId).find("#txt_Description").val().toString();
  1038. }
  1039. else {
  1040. Description = $("#" + instance.g_VisibleContainerId).find(elem).find("#txt_Description").val().toString();
  1041. }
  1042. if (Description == "") {
  1043. Description = row.Description != null ? row.Description : "";
  1044. }
  1045. if (event == "PendingPopCancel") {
  1046. IsCheckPendingItems = true;
  1047. }
  1048. let ItemData = {
  1049. OrderItemId: OrderItemId,
  1050. ItemIndex: ItemIndex,
  1051. ItemId: ItemId,
  1052. HSNId: row.HSNId,
  1053. ItemName: row.ItemName,
  1054. Packs: Packs,
  1055. Pieces: Pieces,
  1056. PriceListId: row.PriceListId,
  1057. UnitPrice: UnitPrice,
  1058. UnitPriceWithOutTax: UnitPriceWithOutTax,
  1059. ExpectedPrice: row.UnitPrice,
  1060. ActualPrice: row.UnitPrice,
  1061. PackCount: row.PackCount,
  1062. PackSize: row.PackSize,
  1063. UnitName: row.UnitName,
  1064. Quantity: Quantity,
  1065. SKU: row.SKU,
  1066. PartNo: PartNo,
  1067. Amount: Amount,
  1068. AmountWithDiscount: AmountWithDiscount,
  1069. DiscountPercent: DiscountPercent,
  1070. DiscountValue: DiscountValue,
  1071. DiscountType: DiscountType,
  1072. DiscountAmount: DiscountAmount,
  1073. ItemValueAfterDiscount: AfterDiscountValue,
  1074. StrTaxPercents: StrTaxPercents,
  1075. AvailableQuantity: row.AvailableQuantity,
  1076. AvailablePacks: row.AvailablePacks,
  1077. AvailablePieces: row.AvailablePieces,
  1078. TotalAvailablePieces: row.TotalAvailablePieces,
  1079. ExchangeDC: IsExchangeDC,
  1080. IsAfterTax: IsAfterTax,
  1081. BaseQty: BaseQty,
  1082. IsFocItem: false,
  1083. optoutAmount: optoutAmount,
  1084. TaxGroupId: TaxGroupId,
  1085. TaxGroupName: TaxGroupName,
  1086. TaxAmount: TaxAmount,
  1087. TaxRateAmount: TaxRateAmount,
  1088. TaxRate: row.TaxRate,
  1089. TaxPercentage: row.TaxPercentage,
  1090. IsOfferAvailable: row.IsOfferAvailable,
  1091. Description: Description == undefined ? "" : Description,
  1092. Discountable: row.Discountable,
  1093. PiecePrice: row.PiecePrice,
  1094. CompositePrice: row.CompositePrice,
  1095. CompositePiecePrice: row.CompositePiecePrice,
  1096. IsCheckPendingItems: IsCheckPendingItems,
  1097. IsError: false,
  1098. ErrorMsg: "",
  1099. ErrorClass: "text-danger",
  1100. IsTaxError: IsTaxError,
  1101. IsLeverageError: IsLeverageError,
  1102. IsFocAdded: false,
  1103. RefOrderItemId: RefOrderItemId,
  1104. RefItemIds: "",
  1105. RefItemSKUs: "",
  1106. FocItemIds: "",
  1107. DiscountGroupId: 0,
  1108. IsOfferDiscountApplied: false,
  1109. AppliedOfferVolume: 0,
  1110. AppliedPlanVolumeId: 0,
  1111. AppliedOfferId: 0,
  1112. optoutOfferGroupId: 0,
  1113. SuggestedPacks: PurPlanRow.SuggestedPacks,
  1114. MinPacks: PurPlanRow.MinPacks,
  1115. AvgPacks: PurPlanRow.AvgPacks,
  1116. InwardOrderPacks: PurPlanRow.InwardOrderPacks,
  1117. OutwardOrderPacks: PurPlanRow.OutwardOrderPacks,
  1118. IsManualUOM: row.IsManualUOM,
  1119. UOMs: row.UOMs,
  1120. IsMultipleUOMs: row.IsMultipleUOMs,
  1121. UOMSchemaId: row.UOMSchemaId,
  1122. MultipleUOMs: row.MultipleUOMs,
  1123. SelectedUnitId: SelectedUnitId,
  1124. SelectedUnitName: SelectedUnitName == "" ? row.UnitName : SelectedUnitName,
  1125. DefaultSize: DefaultSize,
  1126. IsBoMAvailable: row.IsBoMAvailable,
  1127. IsSpecialPrice: row.IsSpecialPrice,
  1128. ConversionQuantity: UOMQuantity,
  1129. RowTotal: 0,
  1130. RowDiscount: 0,
  1131. TaxTotal: 0
  1132. };
  1133. if (SelectedItems_Index == -1) {
  1134. instance.g_SelectedItems.push(ItemData);
  1135. }
  1136. else {
  1137. instance.g_SelectedItems[SelectedItems_Index] = ItemData;
  1138. }
  1139. if (CartItems_Index == -1) {
  1140. instance.g_CartItems_New.push(ItemData);
  1141. }
  1142. else {
  1143. instance.g_CartItems_New[CartItems_Index] = ItemData;
  1144. }
  1145. let ItemElm = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId);
  1146. if (ItemElm.length > 0) {
  1147. instance.updateItemsDesign(ItemElm, event);
  1148. }
  1149. let IsCart = false;
  1150. if ($("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").is(":visible")) {
  1151. IsCart = true;
  1152. }
  1153. if (!FromWidget) {
  1154. if (instance.g_CartItems_New.length == 0) {
  1155. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").html('<li id="0" class="cartitem list-group-item col-xs-12 hidden clear no-border"></li> <li class="list-group-item col-xs-12 no-border EmptyCartLi"><strong>Your Shopping Cart is empty.</strong></li>');
  1156. }
  1157. else {
  1158. $("#" + instance.g_VisibleContainerId).find(".EmptyCartLi").remove();
  1159. }
  1160. if ($("#" + instance.g_VisibleContainerId).find("#cartItemsSearch").val() != undefined) {
  1161. let value = $("#" + instance.g_VisibleContainerId).find("#cartItemsSearch").val().toString().toLowerCase();
  1162. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart li:not(:first-child)").filter(function () {
  1163. $("#" + instance.g_VisibleContainerId).find(this).toggle($("#" + instance.g_VisibleContainerId).find(this).text().toLowerCase().indexOf(value) > -1);
  1164. });
  1165. }
  1166. if (IsCheckPendingItems && $("#" + instance.g_VisibleContainerId).find(".bootbox-confirm").length == 0 && BaseQty != 0 && (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Purchase)) {
  1167. if (!IsTaxError && event != "PendingPopCancel") {
  1168. instance.checkPendingPopup(ItemId, CartItems_Index, FromWidget);
  1169. }
  1170. }
  1171. else {
  1172. if (CartItems_Index != -1) {
  1173. let Cart_elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId);
  1174. if (Cart_elem.length > 0 && !FromWidget) {
  1175. let evnt = "EditCartItem";
  1176. if (event == "RefreshAllItems_InventoryClickEvents") {
  1177. evnt = event;
  1178. }
  1179. instance.updateItemsDesign(Cart_elem, evnt, true);
  1180. }
  1181. }
  1182. else {
  1183. instance.addCartItem(ItemId);
  1184. }
  1185. }
  1186. }
  1187. else {
  1188. if (IsCheckPendingItems && $("#" + instance.g_VisibleContainerId).find(".bootbox-confirm").length == 0) {
  1189. if (!IsTaxError && event != "PendingPopCancel") {
  1190. instance.checkPendingPopup(ItemId, CartItems_Index, FromWidget);
  1191. }
  1192. }
  1193. }
  1194. if (BaseQty != 0) {
  1195. instance.checkValidations(ItemId, false);
  1196. instance.checkValidations(ItemId, true);
  1197. }
  1198. else {
  1199. instance.checkEnablePieces();
  1200. instance.checkEnablePacks();
  1201. }
  1202. if (!instance._order.g_IsPointsOrder && (IsCart || FromWidget || instance.g_FromContinueShopping)) {
  1203. if (row.IsOfferAvailable && !FromWidget) {
  1204. instance.checkOffers(FromWidget, "UpdateItemsArray");
  1205. }
  1206. else if (FromWidget) {
  1207. instance.checkOffers(FromWidget, "UpdateItemsArray");
  1208. }
  1209. else {
  1210. if (IsCart || instance._order.g_IsPurchasePlanning) {
  1211. if (event != "PurPlan_AllItems") {
  1212. instance.getTotals(ItemId);
  1213. }
  1214. }
  1215. }
  1216. }
  1217. else {
  1218. if (IsCart || instance._order.g_IsPurchasePlanning) {
  1219. if (event != "PurPlan_AllItems") {
  1220. if (BaseQty != 0) {
  1221. $("#" + instance.g_VisibleContainerId).find(elem).find(".chk_PurPlanItem").prop("checked", true);
  1222. }
  1223. else {
  1224. $("#" + instance.g_VisibleContainerId).find(elem).find(".chk_PurPlanItem").prop("checked", false);
  1225. }
  1226. instance.getTotals(ItemId);
  1227. }
  1228. }
  1229. }
  1230. if (event == "FromWidget") {
  1231. if (SelectedItems_Index != -1) {
  1232. instance.g_SelectedItems[SelectedItems_Index].IsCheckPendingItems = true;
  1233. }
  1234. if (CartItems_Index == -1) {
  1235. instance.g_CartItems_New[CartItems_Index].IsCheckPendingItems = true;
  1236. }
  1237. }
  1238. instance.g_CartItems_New.filter(x => x.BaseQty == 0).forEach(function (c) {
  1239. let ItemId = c.ItemId;
  1240. let ItemElm = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId);
  1241. let CartElm = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId);
  1242. $("#" + instance.g_VisibleContainerId).find(ItemElm).find(".divOrders_ItemCount").removeClass("floating-label-form-group-with-value");
  1243. $("#" + instance.g_VisibleContainerId).find(CartElm).find(".divOrders_ItemCount").removeClass("floating-label-form-group-with-value");
  1244. });
  1245. }
  1246. getInventoryDesign(ItemId, IsCart, SuggestedPacks = 0, RefItemIds) {
  1247. let instance = this;
  1248. let html = "";
  1249. let InvType = "", fltngclass_Cartons = "", fltngclass_Pieces = "", PP_Cartons = "", PP_Pieces = "", IsFocItem = false, DisableQuantityTxtBox = "", HideMinusPlusBtns = "";
  1250. if (SuggestedPacks != 0) {
  1251. PP_Cartons = SuggestedPacks.toString();
  1252. }
  1253. let CartItem_Index = -1;
  1254. CartItem_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds == RefItemIds);
  1255. let InventoryTypeId = instance._order.g_InventoryApplyType;
  1256. let CartItem = instance.g_CartItems_New[CartItem_Index];
  1257. if (CartItem != undefined) {
  1258. PP_Cartons = CartItem.Packs.toString();
  1259. PP_Pieces = CartItem.Pieces.toString();
  1260. IsFocItem = CartItem.IsFocItem;
  1261. if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1262. PP_Cartons = CartItem.Quantity.toString();
  1263. }
  1264. }
  1265. if (PP_Cartons == "0") {
  1266. PP_Cartons = "";
  1267. }
  1268. if (PP_Cartons != "") {
  1269. fltngclass_Cartons = "floating-label-form-group-with-value";
  1270. }
  1271. if (PP_Pieces == "0") {
  1272. PP_Pieces = "";
  1273. }
  1274. if (PP_Pieces != "") {
  1275. fltngclass_Pieces = "floating-label-form-group-with-value";
  1276. }
  1277. if (IsFocItem) {
  1278. DisableQuantityTxtBox = "disabled style='cursor:not-allowed'";
  1279. HideMinusPlusBtns = "hidden";
  1280. }
  1281. let IsEnablePacks = instance.g_IsEnablePacks, IsEnablePieces = instance.g_IsEnablePieces;
  1282. if (IsFocItem) {
  1283. InventoryTypeId = Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity;
  1284. IsEnablePacks = true;
  1285. IsEnablePieces = false;
  1286. }
  1287. if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs || InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces || InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.PacksAndPieces) {
  1288. if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces && !instance.g_IsEnablePacks) {
  1289. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").removeClass("hidden").removeClass("col-sm-6").addClass("col-sm-12").removeClass("pr-90");
  1290. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").addClass("hidden").removeClass("pl-40");
  1291. $("#" + instance.g_VisibleContainerId).find(".ItemDetails").addClass("col-sm-8").removeClass("col-sm-6");
  1292. $("#" + instance.g_VisibleContainerId).find(".InventoryTypesTextboxes").addClass("col-sm-4").removeClass("col-sm-6");
  1293. }
  1294. else if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs && !instance.g_IsEnablePieces) {
  1295. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").addClass("hidden").removeClass("pr-90");
  1296. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").removeClass("hidden").removeClass("col-sm-6").addClass("col-sm-12").removeClass("pl-40");
  1297. $("#" + instance.g_VisibleContainerId).find(".ItemDetails").addClass("col-sm-8").removeClass("col-sm-6");
  1298. $("#" + instance.g_VisibleContainerId).find(".InventoryTypesTextboxes").addClass("col-sm-4").removeClass("col-sm-6");
  1299. }
  1300. else if (instance.g_IsEnablePacks && instance.g_IsEnablePieces) {
  1301. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").removeClass("hidden").removeClass("col-sm-12").addClass("col-sm-6").addClass("pr-90");
  1302. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").removeClass("hidden").removeClass("col-sm-12").addClass("col-sm-6").addClass("pl-40");
  1303. $("#" + instance.g_VisibleContainerId).find(".ItemDetails").removeClass("col-sm-8").addClass("col-sm-6");
  1304. $("#" + instance.g_VisibleContainerId).find(".InventoryTypesTextboxes").removeClass("col-sm-4").addClass("col-sm-6");
  1305. }
  1306. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").text("Cartons");
  1307. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").text("Pieces");
  1308. }
  1309. else if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1310. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").text("Quantity");
  1311. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").addClass("hidden");
  1312. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").removeClass("hidden").removeClass("col-sm-6").addClass("col-sm-12");
  1313. }
  1314. if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1315. InvType = "Quantity";
  1316. }
  1317. else if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs) {
  1318. InvType = "Cartons";
  1319. }
  1320. else if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces) {
  1321. InvType = "Pieces";
  1322. }
  1323. let cartItemQtyClass = "";
  1324. if (IsCart) {
  1325. cartItemQtyClass = "_editCartItemQuantity";
  1326. }
  1327. if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1328. html += '<div class="col-sm-12 ' + cartItemQtyClass + '">' +
  1329. '<div class="floating-label-form-group defaultSelectedCartons divOrders_ItemCount ' + fltngclass_Cartons + '">' +
  1330. '<label class="text-center">' + InvType + '</label>' +
  1331. '<div class="input-group" id="div_Cartons">' +
  1332. '<span class="input-group-prepend">' +
  1333. '<a href="javascript:;" class="input-group-addon btn quantity-minus "' + HideMinusPlusBtns + ' draggable="false"><i class="fa fa-minus"></i></a>' +
  1334. '</span>' +
  1335. '<input type="text" id="txt_Cartons" ' + DisableQuantityTxtBox + 'class="form-control text-center txtOrder_ItemCount floating-label-control" inputmode="numeric" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" oninput = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" data-isdynamic="false" placeholder="' + InvType + '" data-placeholder="' + InvType + '" data-label="' + InvType + '"value=' + PP_Cartons + '>' +
  1336. '<span class="input-group-append">' +
  1337. '<a href="javascript:;" class="quantity-plus input-group-addon btn "' + HideMinusPlusBtns + ' draggable="false"><i class="fa fa-plus"></i></a>' +
  1338. '</span>' +
  1339. '</div>' +
  1340. '</div>' +
  1341. '</div>';
  1342. }
  1343. else if (IsEnablePacks && !IsEnablePieces && InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs) {
  1344. html += '<div class="col-sm-12 ' + cartItemQtyClass + '">' +
  1345. '<div class="floating-label-form-group defaultSelectedCartons divOrders_ItemCount ' + fltngclass_Cartons + '">' +
  1346. '<label class="text-center">' + InvType + '</label>' +
  1347. '<div class="input-group" id="div_Cartons">' +
  1348. '<span class="input-group-prepend">' +
  1349. '<a href="javascript:;" class="input-group-addon btn quantity-minus "' + HideMinusPlusBtns + ' draggable="false"><i class="fa fa-minus"></i></a>' +
  1350. '</span>' +
  1351. '<input type="text" id="txt_Cartons" ' + DisableQuantityTxtBox + 'class="form-control text-center txtOrder_ItemCount floating-label-control" inputmode="numeric" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" oninput = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" data-isdynamic="false" placeholder="' + InvType + '" data-placeholder="' + InvType + '" data-label="' + InvType + '"value=' + PP_Cartons + '>' +
  1352. '<span class="input-group-append">' +
  1353. '<a href="javascript:;" class="quantity-plus input-group-addon btn "' + HideMinusPlusBtns + ' draggable="false"><i class="fa fa-plus"></i></a>' +
  1354. '</span>' +
  1355. '</div>' +
  1356. '</div>' +
  1357. '</div>';
  1358. }
  1359. else if (!IsEnablePacks && IsEnablePieces) {
  1360. html += '<div class="col-sm-12 ' + cartItemQtyClass + '">' +
  1361. '<div class="floating-label-form-group defaultSelectedPieces divOrders_ItemPieceCount ' + fltngclass_Pieces + '">' +
  1362. '<label class="text-center">' + InvType + '</label>' +
  1363. '<div class="input-group" id="div_Pieces">' +
  1364. '<span class="input-group-prepend">' +
  1365. '<a href="javascript:;" class="input-group-addon btn quantity-minus" draggable="false"><i class="fa fa-minus"></i></a>' +
  1366. '</span>' +
  1367. '<input type="text" id="txt_Pieces" class="form-control text-center txtOrder_ItemPieceCount floating-label-control" inputmode="numeric" data-isdynamic="false" placeholder="' + InvType + '" data-placeholder="' + InvType + '" data-label="' + InvType + '" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" value=' + PP_Pieces + '>' +
  1368. '<span class="input-group-append">' +
  1369. '<a href="javascript:;" class="quantity-plus input-group-addon btn" draggable="false"><i class="fa fa-plus"></i></a>' +
  1370. '</span>' +
  1371. '</div>' +
  1372. '</div>' +
  1373. '</div>';
  1374. }
  1375. if ((IsEnablePacks && IsEnablePieces) && InventoryTypeId != Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1376. html += '<div class="col-sm-12 ' + cartItemQtyClass + '"><div class="row"><div class="col-6">' +
  1377. '<div class="floating-label-form-group defaultSelectedCartons divOrders_ItemCount ' + fltngclass_Cartons + '">' +
  1378. '<label class="text-center pl-40">Cartons</label>' +
  1379. '<div class="input-group" id="div_Cartons">' +
  1380. '<span class="input-group-prepend">' +
  1381. '<a href="javascript:;" class="input-group-addon btn quantity-minus" draggable="false"><i class="fa fa-minus"></i></a>' +
  1382. '</span>' +
  1383. '<input type="text" id="txt_Cartons" class="form-control text-center txtOrder_ItemCount floating-label-control" inputmode="numeric" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" oninput = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" data-isdynamic="false" placeholder="Cartons" data-placeholder="Cartons" data-label="Cartons" value=' + PP_Cartons + '>' +
  1384. '</div>' +
  1385. '</div>' +
  1386. ' </div>';
  1387. html +=
  1388. '<div class="col-6 ' + cartItemQtyClass + '">' +
  1389. '<div class="floating-label-form-group defaultSelectedPieces divOrders_ItemPieceCount ' + fltngclass_Pieces + '"> ' +
  1390. '<label class="text-center pr-20">Pieces</label>' +
  1391. '<div class="input-group" id="div_Pieces">' +
  1392. '<input type="text" id="txt_Pieces" class="form-control text-center floating-label-control txtOrder_ItemPieceCount" inputmode="numeric" data-isdynamic="false" style = "margin-left: 13px;" placeholder="Pieces" data-placeholder="Pieces" data-label="Pieces" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" value=' + PP_Pieces + '>' +
  1393. '<span class="input-group-append">' +
  1394. '<a href="javascript:;" class="quantity-plus input-group-addon btn" draggable="false"><i class="fa fa-plus"></i></a>' +
  1395. '</span>' +
  1396. '</div>' +
  1397. '</div>' +
  1398. '</div>' +
  1399. '</div>' +
  1400. '</div>';
  1401. }
  1402. html += '</div>';
  1403. return html;
  1404. }
  1405. getInventoryDesignWithTokens_PurchasePlan() {
  1406. let instance = this;
  1407. let html = "";
  1408. let InvType = "";
  1409. let InventoryTypeId = instance._order.g_InventoryApplyType;
  1410. let IsEnablePacks = instance.g_IsEnablePacks, IsEnablePieces = instance.g_IsEnablePieces;
  1411. if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs || InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces || InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.PacksAndPieces) {
  1412. if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces && !instance.g_IsEnablePacks) {
  1413. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").removeClass("hidden").removeClass("col-sm-6").addClass("col-sm-12").removeClass("pr-90");
  1414. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").addClass("hidden").removeClass("pl-40");
  1415. $("#" + instance.g_VisibleContainerId).find(".ItemDetails").addClass("col-sm-8").removeClass("col-sm-6");
  1416. $("#" + instance.g_VisibleContainerId).find(".InventoryTypesTextboxes").addClass("col-sm-4").removeClass("col-sm-6");
  1417. }
  1418. else if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs && !instance.g_IsEnablePieces) {
  1419. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").addClass("hidden").removeClass("pr-90");
  1420. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").removeClass("hidden").removeClass("col-sm-6").addClass("col-sm-12").removeClass("pl-40");
  1421. $("#" + instance.g_VisibleContainerId).find(".ItemDetails").addClass("col-sm-8").removeClass("col-sm-6");
  1422. $("#" + instance.g_VisibleContainerId).find(".InventoryTypesTextboxes").addClass("col-sm-4").removeClass("col-sm-6");
  1423. }
  1424. else if (instance.g_IsEnablePacks && instance.g_IsEnablePieces) {
  1425. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").removeClass("hidden").removeClass("col-sm-12").addClass("col-sm-6").addClass("pr-90");
  1426. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").removeClass("hidden").removeClass("col-sm-12").addClass("col-sm-6").addClass("pl-40");
  1427. $("#" + instance.g_VisibleContainerId).find(".ItemDetails").removeClass("col-sm-8").addClass("col-sm-6");
  1428. $("#" + instance.g_VisibleContainerId).find(".InventoryTypesTextboxes").removeClass("col-sm-4").addClass("col-sm-6");
  1429. }
  1430. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").text("Cartons");
  1431. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").text("Pieces");
  1432. }
  1433. else if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1434. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").text("Quantity");
  1435. $("#" + instance.g_VisibleContainerId).find("#spn_picesTitle").addClass("hidden");
  1436. $("#" + instance.g_VisibleContainerId).find("#spn_InventoryTitle").removeClass("hidden").removeClass("col-sm-6").addClass("col-sm-12");
  1437. }
  1438. if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1439. InvType = "Quantity";
  1440. }
  1441. else if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs) {
  1442. InvType = "Cartons";
  1443. }
  1444. else if (InventoryTypeId == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces) {
  1445. InvType = "Pieces";
  1446. }
  1447. if (IsEnablePacks && !IsEnablePieces) {
  1448. html += '<div class="col-sm-12">' +
  1449. '<div class="floating-label-form-group defaultSelectedCartons divOrders_ItemCount {{fltngclass_Cartons}}">' +
  1450. '<label class="text-center">' + InvType + '</label>' +
  1451. '<div class="input-group" id="div_Cartons">' +
  1452. '<span class="input-group-prepend">' +
  1453. '<a href="javascript:;" class="input-group-addon btn quantity-minus" draggable="false"><i class="fa fa-minus"></i></a>' +
  1454. '</span>' +
  1455. '<input type="text" id="txt_Cartons" class="form-control text-center txtOrder_ItemCount floating-label-control" inputmode="numeric" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" oninput = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" data-isdynamic="false" placeholder="' + InvType + '" data-placeholder="' + InvType + '" data-label="' + InvType + '" value={{PP_Cartons}}>' +
  1456. '<span class="input-group-append">' +
  1457. '<a href="javascript:;" class="quantity-plus input-group-addon btn" draggable="false"><i class="fa fa-plus"></i></a>' +
  1458. '</span>' +
  1459. '</div>' +
  1460. '</div>' +
  1461. '</div>';
  1462. }
  1463. else if (!IsEnablePacks && IsEnablePieces) {
  1464. html += '<div class="col-sm-12">' +
  1465. '<div class="floating-label-form-group defaultSelectedPieces divOrders_ItemPieceCount {{fltngclass_Pieces}}">' +
  1466. '<label class="text-center">' + InvType + '</label>' +
  1467. '<div class="input-group" id="div_Pieces">' +
  1468. '<span class="input-group-prepend">' +
  1469. '<a href="javascript:;" class="input-group-addon btn quantity-minus" draggable="false"><i class="fa fa-minus"></i></a>' +
  1470. '</span>' +
  1471. '<input type="text" id="txt_Pieces" class="form-control text-center txtOrder_ItemPieceCount floating-label-control" inputmode="numeric" data-isdynamic="false" placeholder="' + InvType + '" data-placeholder="' + InvType + '" data-label="' + InvType + '" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" value={{PP_Pieces}}>' +
  1472. '<span class="input-group-append">' +
  1473. '<a href="javascript:;" class="quantity-plus input-group-addon btn" draggable="false"><i class="fa fa-plus"></i></a>' +
  1474. '</span>' +
  1475. '</div>' +
  1476. '</div>' +
  1477. '</div>';
  1478. }
  1479. if (IsEnablePacks && IsEnablePieces) {
  1480. html += '<div class="col-sm-12"><div class="row"><div class="col-6">' +
  1481. '<div class="floating-label-form-group defaultSelectedCartons divOrders_ItemCount {{fltngclass_Cartons}}">' +
  1482. '<label class="text-center pl-40">Cartons</label>' +
  1483. '<div class="input-group" id="div_Cartons">' +
  1484. '<span class="input-group-prepend">' +
  1485. '<a href="javascript:;" class="input-group-addon btn quantity-minus" draggable="false"><i class="fa fa-minus"></i></a>' +
  1486. '</span>' +
  1487. '<input type="text" id="txt_Cartons" class="form-control text-center txtOrder_ItemCount floating-label-control" inputmode="numeric" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" oninput = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" data-isdynamic="false" placeholder="Cartons" data-placeholder="Cartons" data-label="Cartons" value={{PP_Cartons}}>' +
  1488. '</div>' +
  1489. '</div>' +
  1490. ' </div>';
  1491. html +=
  1492. '<div class="col-6">' +
  1493. '<div class="floating-label-form-group defaultSelectedPieces divOrders_ItemPieceCount {{fltngclass_Pieces}}"> ' +
  1494. '<label class="text-center pr-20">Pieces</label>' +
  1495. '<div class="input-group" id="div_Pieces">' +
  1496. '<input type="text" id="txt_Pieces" class="form-control text-center floating-label-control txtOrder_ItemPieceCount" inputmode="numeric" data-isdynamic="false" style="margin-left: 13px;" placeholder="Pieces" data-placeholder="Pieces" data-label="Pieces" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" value={{PP_Pieces}}>' +
  1497. '<span class="input-group-append">' +
  1498. '<a href="javascript:;" class="quantity-plus input-group-addon btn" draggable="false"><i class="fa fa-plus"></i></a>' +
  1499. '</span>' +
  1500. '</div>' +
  1501. '</div>' +
  1502. '</div>' +
  1503. '</div>' +
  1504. '</div>';
  1505. }
  1506. html += '</div>';
  1507. return html;
  1508. }
  1509. getItemDesign(res, FromWidget = false, IsCart = false) {
  1510. let instance = this;
  1511. let html = "";
  1512. let data = res;
  1513. let ItemId = data.ItemId;
  1514. let InventoryType = instance._order.g_InventoryApplyType;
  1515. let url = '';
  1516. let ItemImg = "";
  1517. let LoadedItemIndex = instance.g_LoadedItems.findIndex(x => x.ItemId == ItemId);
  1518. if (LoadedItemIndex != -1) {
  1519. url = instance.g_LoadedItems[LoadedItemIndex].ImageUrl;
  1520. if (url == "" || url == undefined || url == null) {
  1521. ItemImg = ``;
  1522. }
  1523. else {
  1524. ItemImg = `<img class="avatar" style="width:70px;height:70px;" onerror="ReloadImage(event)" data-dynamic="1" src="` + url + `">`;
  1525. }
  1526. }
  1527. else {
  1528. if (data.ImageUrl == "" || data.ImageUrl == undefined || data.ImageUrl == null) {
  1529. ItemImg = ``;
  1530. }
  1531. else {
  1532. url = data.ImageUrl;
  1533. ItemImg = `<img class="avatar" style="width:70px;height:70px;" onerror="ReloadImage(event)" data-dynamic="1" src="` + url + `">`;
  1534. }
  1535. }
  1536. let hidden = "";
  1537. let OrderQuantity = "";
  1538. let multiplevalue = "";
  1539. let Mod_UnitPrice = 0;
  1540. let Items_up = instance.g_ItemsUnitPrice_New.filter(x => x.ItemId == data.ItemId);
  1541. if (Items_up.length == 0) {
  1542. Mod_UnitPrice = data.UnitPrice;
  1543. instance.g_ItemsUnitPrice_New.push({
  1544. ItemId: ItemId,
  1545. UnitPrice: data.UnitPrice,
  1546. TaxRateAmount: data.TaxRateAmount
  1547. });
  1548. }
  1549. else {
  1550. Mod_UnitPrice = Items_up[0].UnitPrice;
  1551. }
  1552. if (instance._order.g_IsPurchasePlanning) {
  1553. if ((res.SuggestedPacks) != 0 && (res.SuggestedPacks) != null && (res.SuggestedPacks) != undefined) {
  1554. let unitprice = Number(Mod_UnitPrice);
  1555. let packCount = Number(data.PackCount);
  1556. let packSize = Number(data.PackSize);
  1557. let baseqty = packCount * packSize * res.SuggestedPacks;
  1558. OrderQuantity = " X " + (baseqty);
  1559. multiplevalue = " = " + (unitprice * baseqty);
  1560. }
  1561. }
  1562. let LiClass = "variant-item variant-addeditem variant-addeditem-" + ItemId;
  1563. let EditUnitPriceClass = 'editItemPriceAccordion_';
  1564. let AvailClass = "ItemAvailability";
  1565. let ExchangeClass = "chkItem_ExchangeDC_" + ItemId;
  1566. let HideDeleteBtn = "";
  1567. let RefItemIds = data.RefItemIds;
  1568. if (RefItemIds == undefined) {
  1569. RefItemIds = "";
  1570. }
  1571. if (IsCart) {
  1572. LiClass = "cartitem cartitem-" + ItemId;
  1573. EditUnitPriceClass = 'editCartItemPriceAccordion_';
  1574. AvailClass = "CartAvailability";
  1575. ExchangeClass = "chkCartItem_ExchangeDC_" + ItemId;
  1576. if (data.IsFocItem) {
  1577. HideDeleteBtn = "hidden";
  1578. if (RefItemIds != "") {
  1579. LiClass = "cartitem cartitem-" + ItemId + "-" + RefItemIds.replace(/,/g, "-");
  1580. }
  1581. }
  1582. }
  1583. else if (FromWidget) {
  1584. if (Bizgaze.Apps.Transact.Controls.AddOrderItems.Instance().g_Edit_OrderItemId > 0) {
  1585. HideDeleteBtn = "hidden";
  1586. }
  1587. if (RefItemIds != "") {
  1588. LiClass = "variant-item variant-addeditem variant-addeditem-" + ItemId + "-" + RefItemIds.replace(/,/g, "-");
  1589. }
  1590. }
  1591. html = '<li id="' + ItemId + '" class="list-group-item ' + LiClass + ' li no-border">' +
  1592. '<input type="hidden" class="hfOrder_ItemId" value="' + ItemId + '" />' +
  1593. '<input type="hidden" class="hfOrder_RefItemId" value="' + RefItemIds + '" />' +
  1594. '<input type="hidden" class="hfOrder_ItemName" value="' + data.ItemName + '" />' +
  1595. '<input type="hidden" class="hfOrder_ItemSKU" value="' + data.SKU + '" />';
  1596. let DivClass = 'col-sm-8';
  1597. let InventoryTypeDivClass = 'col-sm-4';
  1598. if (instance.g_IsEnablePacks && instance.g_IsEnablePieces) {
  1599. DivClass = 'col-sm-6';
  1600. InventoryTypeDivClass = 'col-sm-6';
  1601. }
  1602. if (`${ItemImg}`.length == 0) {
  1603. html += `<div class="row position-relative">
  1604. <div class="position-absolute t-0 z-index-1" style="right: 10px;"><a href="javascript:;" class="btn btn-icon btn-flush-biz-theme btn-rounded flush-soft-hover d-30 cart-item-remove d-none"><span class="btn-icon-wrap"><i class="fa fa-times text-danger"></i></span></a><input type="checkbox" class="cart-item-chk d-none" id="cartItemChk_${ItemId}" style="transform: scale(1.3);"/></div>
  1605. <div class="ItemDetails ${DivClass} d-flex" id="ItemDetails">
  1606. <div class="img_div_tag_${ItemId} d-none"><a class="pull-left" style="cursor:pointer;height:80px; width:80px;"onclick="Bizgaze.Apps.Transact.Controls.OrderItems.Instance().getItemPreview(${ItemId});">${ItemImg}</a></div>`;
  1607. }
  1608. else {
  1609. html += `<div class="row position-relative">
  1610. <div class="position-absolute t-0 z-index-1" style="right: 10px;"><a href="javascript:;" class="btn btn-icon btn-flush-biz-theme btn-rounded flush-soft-hover d-30 cart-item-remove d-none"><span class="btn-icon-wrap"><i class="fa fa-times text-danger"></i></span></a><input type="checkbox" class="cart-item-chk d-none" id="cartItemChk_${ItemId}" style="transform: scale(1.3);"/></div>
  1611. <div class="ItemDetails ${DivClass} d-flex" id="ItemDetails">
  1612. <div class="img_div_tag_${ItemId}"><a class="pull-left" style="cursor:pointer;height:80px; width:80px;"onclick="Bizgaze.Apps.Transact.Controls.OrderItems.Instance().getItemPreview(${ItemId});">${ItemImg}</a></div>`;
  1613. }
  1614. let deleteBtnHtml = '';
  1615. if (IsCart || FromWidget) {
  1616. deleteBtnHtml += '<a href="javascript:;" id="deleteCartItem"><span class="pa-5 delete ' + HideDeleteBtn + '" style="cursor:Pointer;" title="Remove Item"><i class="m-r fa fa-trash text-danger fa-lg" id=""></i></span></a>';
  1617. }
  1618. if (!instance._order.g_IsPurchasePlanning) {
  1619. if ($(window).width() < 768) {
  1620. html += `<div><div><div>${deleteBtnHtml}</div><span class="block text-sm mouseHoverClass CartItemName order-cart-name font-weight-600 font-14 text-dark">${data.ItemName}</span><span class="ml-2 sales-is-offer-avail">`;
  1621. }
  1622. else {
  1623. html += `<div><div><div>${deleteBtnHtml}</div><span class="block text-sm mouseHoverClass CartItemName order-cart-name font-weight-600 font-14 text-dark">${data.ItemName}</span><span class="ml-2 sales-is-offer-avail">`;
  1624. }
  1625. }
  1626. else {
  1627. html += 'div class="d-flex"><div><span> <strong> Edit </strong><span> <i class="fa fa-pencil ml-10"> </i> </span> </span> <br/> <input type="checkbox" id="chk_PurPlanItem_' + ItemId + '" class="chk_PurPlanItem css-checkbox"/>' +
  1628. '<span class="ml-10 pull-right text-danger tax-error"></span><span class="block text-sm ml-2 mouseHoverClass CartItemName" style="color: #5ba8fb;">' + data.ItemName + '</span></div><div class="ml-2 text-right sales-is-offer-avail">';
  1629. }
  1630. if (data.IsOfferAvailable == true && (data.RefItemId == undefined || data.RefItemId == 0)) {
  1631. if (instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim && instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  1632. html += '<input type="hidden" class="IsOfferAvailableItem" value="true">';
  1633. html += '<a class="btn btn-xs btn-outline-primary line-height-12 font-10 offerBadge_cls" onclick="Bizgaze.Apps.Transact.Controls.OrderItems.Instance().showOfferItems(' + instance._order.g_OrganizationId + ',' + ItemId + ",'" + data.ItemName + "'," + instance._order.g_OrderTypeId + ',' + 'this)"><span class="count"><i class="la la-award"></i> offer</span></a>';
  1634. }
  1635. }
  1636. if (data.IsBoMAvailable) {
  1637. if (instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim && instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  1638. html += '<a class="btn btn-xs line-height-12 font-10 btn-outline-info ml-2" onclick="Bizgaze.Apps.Transact.Controls.OrderItems.Instance().showBOMItems(' + ItemId + ",'" + data.ItemName + "'" + ')"><span class=" count" > BOM </span></a>';
  1639. }
  1640. }
  1641. if (data.IsSpecialPrice && instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim && instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim)
  1642. html += '<span class="btn btn-xs up btn-outline-blue line-height-12 font-10 ml-2 btnItemSpecial ">SP</span>';
  1643. html += '<span class="font-10 focBadge hidden"><span class="text-warning up m-l-n-sm ml-2 count" style="">Free of SKU - <span id="FocBadgeSKU" class="font-10"> </span> </span></span>';
  1644. html += '</span></div>';
  1645. if (data.PartNo != "" && data.PartNo != null) {
  1646. html += '<span class="font-weight-300 font-12">SKU : ' + data.SKU + '</span> <span class="font-weight-300"> ( ' + data.PartNo + ' )';
  1647. }
  1648. else {
  1649. html += '<span class="font-weight-300 font-12">SKU : ' + data.SKU;
  1650. }
  1651. if (instance._order.g_IsAdmin == 1 || instance._order.g_IsShowAvailability == 1) {
  1652. html += ', </span> ';
  1653. }
  1654. if (InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs || InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces || InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.PacksAndPieces) {
  1655. if (instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim && instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  1656. if (instance._order.g_IsAdmin == 1 || instance._order.g_IsShowAvailability == 1) {
  1657. if (instance._order.g_IsPurchasePlanning) {
  1658. html += `<span class="font-12 ` + AvailClass + `">Avail : ` + data.AvailablePacks + ` / ` + data.AvailablePieces + ` (` + data.AvailableQuantity + `)` + ` Pur PO: <a onclick='var filter = []; filter.push({"Key" : "estimateid", "Value": "` + res.EstimateId + `", ExpOp: 1}, {"Key" : "itemid", "Value": "` + ItemId + `", ExpOp: 1}, {"Key" : "ordertypeid", "Value": "2", ExpOp: 1}); Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_PurchasePlan_PendingDetails", null, filter, null);' style="color: #5ba8fb;text-decoration: underline;" class="PurPendingOrders">` + res.InwardOrderPacks + `</a> Sales PO: <a onclick='var filter = []; filter.push({"Key" : "estimateid", "Value": "` + res.EstimateId + `", ExpOp: 1}, {"Key" : "itemid", "Value": "` + ItemId + `", ExpOp: 1}, {"Key" : "ordertypeid", "Value": "1", ExpOp: 1}); Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_PurchasePlan_PendingDetails", null, filter, null);' style="color: #5ba8fb;text-decoration: underline;" class="SalesPendingOrders">` + res.OutwardOrderPacks + `</a></span><span class="text-danger pull-right LessUnitPrice-error"></span><br/>`;
  1659. }
  1660. else {
  1661. if (InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces && !instance.g_IsEnablePacks) {
  1662. html += '<span class="font-12 ' + AvailClass + '">Avail : ' + data.TotalAvailablePieces + ' (' + data.AvailableQuantity + ') </span><span class="text-danger pull-right LessUnitPrice-error"></span>';
  1663. }
  1664. else {
  1665. html += '<span class="font-12 ' + AvailClass + '">Avail : ' + data.AvailablePacks + ' / ' + data.AvailablePieces + ' (' + data.AvailableQuantity + ') </span><span class="text-danger pull-right LessUnitPrice-error"></span>';
  1666. }
  1667. }
  1668. }
  1669. }
  1670. else {
  1671. html += '<span class="font-12 ' + AvailClass + '">Claim Avail : ' + data.AvailablePacks + ' / ' + data.AvailablePieces + ' (' + data.AvailableQuantity + ')</span>';
  1672. }
  1673. }
  1674. else if (InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1675. if (instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim && instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  1676. if (instance._order.g_IsAdmin == 1 || instance._order.g_IsShowAvailability == 1) {
  1677. if (instance._order.g_IsPurchasePlanning) {
  1678. html += '<span class="font-12 ' + AvailClass + '">Avail : ' + data.Packs + ' Pur PO: <a href="javascript:;"style="color: #5ba8fb;text-decoration: underline;" class="PendingOrders">' + res.InwardOrderPacks + '</a> Sales PO: <a href="javascript:;"style="color: #5ba8fb;text-decoration: underline;" class="PendingOrders">' + res.OutwardOrderPacks + '</a></span><span class="text-danger pull-right LessUnitPrice-error"></span><br/>';
  1679. }
  1680. else
  1681. html += '<span class="font-12 ' + AvailClass + '">Avail : ' + data.AvailableQuantity + '</span>';
  1682. }
  1683. }
  1684. else
  1685. html += '<span class="font-12 ' + AvailClass + '">Claim Avail : ' + data.AvailableQuantity + '</span>';
  1686. }
  1687. if (instance._order.g_IsPurchasePlanning) {
  1688. html += '<span class="block">MOQ : {{MinPacks}} | ROQ : {{ReorderPacks}} | Suggested : {{SuggestedPacks}} | Avg : {{AvgPacks}} </span>';
  1689. }
  1690. let Price_dataToggle = "";
  1691. if (instance._order.g_IsAdmin == 1 || instance._order.g_ShowPrice == 1) {
  1692. Price_dataToggle = `data-toggle="collapse"`;
  1693. }
  1694. instance.getPriceTypeValues(ItemId);
  1695. let compositeDecimalValue = 0;
  1696. let piecePriceDecimalValue = 0;
  1697. let compositePiecePriceDecimalvalue = 0;
  1698. let Item = instance.g_LoadedItems.find(x => x.ItemId == ItemId);
  1699. if (Item != undefined) {
  1700. compositeDecimalValue = Item.CompositePrice;
  1701. piecePriceDecimalValue = Item.PiecePrice;
  1702. compositePiecePriceDecimalvalue = Item.CompositePiecePrice;
  1703. }
  1704. html += '<br>';
  1705. if (instance.g_IsEnablePiecePrice) {
  1706. if (instance._order.g_IsPurchasePlanning && (res.SuggestedPacks) != 0 && (res.SuggestedPacks) != null && (res.SuggestedPacks) != undefined && Mod_UnitPrice != 0) {
  1707. html += '<span class="sp_PriceType">Piece Price : </span> <span id="DiscountOpenBracket" class="hidden">(</span><a href="javascript:;" class="text-sm editItemPrice" style="text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Number(instance.roundOff(piecePriceDecimalValue)) + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class="' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" >' + OrderQuantity + '</span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" >' + multiplevalue + '</span></span>';
  1708. }
  1709. else
  1710. html += '<span class="sp_PriceType">Piece Price : </span> <span id="DiscountOpenBracket" class="hidden">(</span><a href="javascript:;" class="text-sm editItemPrice" style="text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Number(instance.roundOff(piecePriceDecimalValue)) + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class="' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" ></span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" ></span></span>';
  1711. }
  1712. else if (instance.g_IsEnableCompositePrice) {
  1713. if ((instance._order.g_IsPurchasePlanning && data.SuggestedPacks) != 0 && (data.SuggestedPacks) != null && (data.SuggestedPacks) != undefined && Mod_UnitPrice != 0) {
  1714. html += '<span class="sp_PriceType">Comp. Price : </span> <span id="DiscountOpenBracket" class="hidden">(</span> <a href="javascript:;" class="text-sm editItemPrice " style="text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Number(instance.roundOff(compositeDecimalValue)) + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class="' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" >' + OrderQuantity + '</span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" >' + multiplevalue + '</span></span>';
  1715. }
  1716. else {
  1717. html += '<span class="sp_PriceType">Comp. Price : </span> <span id="DiscountOpenBracket" class="hidden">(</span> <a href="javascript:;" class="text-sm editItemPrice " style="text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Number(instance.roundOff(compositeDecimalValue)) + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class="' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" ></span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" ></span></span>';
  1718. }
  1719. }
  1720. else if (instance.g_IsEnableCompositePiecePrice) {
  1721. if (instance._order.g_IsPurchasePlanning && (data.SuggestedPacks) != 0 && (data.SuggestedPacks) != null && (data.SuggestedPacks) != undefined && Mod_UnitPrice != 0) {
  1722. html += '<span class="sp_PriceType">Comp. Piece Price : </span><span id="DiscountOpenBracket" class="hidden">(</span><a href="javascript:;" class="text-sm editItemPrice CompositePiecePrice" style="color: #5ba8fb;text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Number(instance.roundOff(compositePiecePriceDecimalvalue)) + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class="' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" >' + OrderQuantity + '</span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" >' + multiplevalue + '</span></span>';
  1723. }
  1724. else
  1725. html += '<span class="sp_PriceType">Comp. Piece Price : </span><span id="DiscountOpenBracket" class="hidden">(</span><a href="javascript:;" class="text-sm editItemPrice CompositePiecePrice" style="color: #5ba8fb;text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Number(instance.roundOff(compositePiecePriceDecimalvalue)) + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class="' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" ></span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" ></span></span>';
  1726. }
  1727. else {
  1728. if (instance._order.g_IsPurchasePlanning && (res.SuggestedPacks) != 0 && (res.SuggestedPacks) != null && (res.SuggestedPacks) != undefined && Mod_UnitPrice != 0) {
  1729. html += '<span class="sp_PriceType font-12">Price : </span><span id="DiscountOpenBracket" class="hidden">(</span><a href="javascript:;" class="text-sm editItemPrice font-12 text-dark " style="text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Mod_UnitPrice + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class="' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" >' + OrderQuantity + '</span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" >' + multiplevalue + '</span></span>';
  1730. }
  1731. else {
  1732. let PointsorPrice = "Price";
  1733. if (instance._order.g_IsPointsOrder) {
  1734. PointsorPrice = "Points";
  1735. }
  1736. if (data.IsManualUOM && instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales) {
  1737. html += '<span class="sp_PriceType font-12">' + PointsorPrice + ' : </span><span id="DiscountOpenBracket" class="hidden">(</span><a href="javascript:;" class="text-sm editItemPrice font-12" style="color: #5ba8fb;text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Mod_UnitPrice + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class=" font-12 ' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" ></span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" ></span></span> <span class="ManualUOM_' + ItemId + ' hidden">' + instance.getManualUOMDesign(data) + '</span> <span class="ManualUOM_RowTotal hidden"> </span>';
  1738. }
  1739. else {
  1740. html += '<span class="sp_PriceType font-12">' + PointsorPrice + ' : </span><span id="DiscountOpenBracket" class="hidden">(</span><a href="javascript:;" class="text-sm editItemPrice font-12" style="color: #5ba8fb;text-decoration: underline;"' + Price_dataToggle + 'data-target="#' + EditUnitPriceClass + '' + ItemId + '">' + Mod_UnitPrice + '</a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan" class=" font-12 ' + hidden + '"><span id="OrderQuantity_' + ItemId + '" class="OrderQuantity hidden" ></span><span id="multipliedvalue_' + ItemId + '" class="multipliedvalue hidden" ></span></span>';
  1741. }
  1742. }
  1743. }
  1744. html += '<div id="LeverageErrorTxt" class="text-warning hidden">Leverage % Exceeded</div><div class=" text-danger tax-error"></div>';
  1745. html += '</div>';
  1746. html += '</div>';
  1747. let SuggestedPacks = 0;
  1748. if (instance._order.g_IsPurchasePlanning) {
  1749. SuggestedPacks = res.SuggestedPacks;
  1750. }
  1751. html += '<div id="InventoryTypesTextboxes" class="InventoryTypesTextboxes ' + InventoryTypeDivClass + ' p-0">';
  1752. html += instance.getInventoryDesign(ItemId, IsCart, SuggestedPacks, RefItemIds);
  1753. html += '</div>';
  1754. let classclaim = "";
  1755. if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  1756. classclaim = "col-sm-7";
  1757. }
  1758. else {
  1759. classclaim = "col-sm-2";
  1760. }
  1761. let IsExpandItem = "";
  1762. if (instance._order.g_ExpandItemSettings && (instance._order.g_IsAdmin == 1 || instance._order.g_ShowPrice == 1)) {
  1763. IsExpandItem = "";
  1764. }
  1765. else {
  1766. IsExpandItem = "collapse";
  1767. }
  1768. html += '<div class="row card py-2 mt-2 mb-0 ' + IsExpandItem + '" id="' + EditUnitPriceClass + '' + ItemId + '">' +
  1769. '<div class="col-sm-12 p-0">' +
  1770. '<div class="input-group">' +
  1771. '<div class="col-sm-2">' +
  1772. '<div class="floating-label-form-group floating-label-form-group-with-value">';
  1773. html += '<label for="txt_editItemPrice">Unit price </label><input type="text" id="txt_editItemPrice" class="form-control floating-label-control txteditItemPrice" value="' + Mod_UnitPrice + '" inputmode="numeric" data-isdynamic="false" placeholder="Unit Price" data-placeholder="Enter Unit Price" data-label="Unit Price" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" min="0"></div>';
  1774. let offerDiscountClass = "";
  1775. if (data.IsOfferAvailable && data.IsOfferDiscountApplied && IsCart && !instance._order.g_IsManageOfferDiscount) {
  1776. offerDiscountClass = "readonly";
  1777. }
  1778. let IsDiscountHidden = "";
  1779. if (instance._order.g_IsPointsOrder) {
  1780. IsDiscountHidden = "hidden";
  1781. }
  1782. html += '</div>' +
  1783. '<div class="col-sm-2 ' + IsDiscountHidden + '">' +
  1784. '<div class="floating-label-form-group discountFloatLabels">' +
  1785. '<label>Discount</label>' +
  1786. '<div class="input-group">' +
  1787. '<input type="text" id="Ord_txtdiscount" placeholder="Discount" inputmode="numeric" data-isdynamic="false" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" data-placeholder="0.00" data-label="Discount" class="form-control ord_txtaddldiscount floating-label-control" value="" ' + offerDiscountClass + '>' +
  1788. '<div class="input-group-btn">' +
  1789. '<select class="btnOrder_DiscType mt-10 border-blue"><option value="2">Val</option><option value="1">%</option></select>' +
  1790. '</div>' +
  1791. '</div>' +
  1792. '</div>' +
  1793. '</div>';
  1794. if (instance.g_FromWidgetEditOrderItemId == 0) {
  1795. html += '<div class="' + classclaim + '">' +
  1796. '<div class="floating-label-form-group descriptionFloatLabels">' +
  1797. '<label>Description</label>' +
  1798. '<input type="text" id="txt_Description" class="form-control floating-label-control " data-isdynamic="false" placeholder="Description" data-placeholder="Description" data-label="Description">' +
  1799. '</div>' +
  1800. '</div>';
  1801. }
  1802. offerDiscountClass = "";
  1803. let IsItemExchangable = data.Discountable;
  1804. if (instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim && instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  1805. if ((instance._order.g_IsAdmin == 1 && IsItemExchangable) || (instance._order.g_IsShowExchangeDc == 1 && IsItemExchangable)) {
  1806. html += '<div class="col-sm-2 mt-40">' +
  1807. '<div class="custom-control custom-checkbox checkbox-primary">' +
  1808. '<input type="checkbox" class="custom-control-input chkItem_ExchangeDC" id="' + ExchangeClass + '">' +
  1809. '<label class="custom-control-label lbl_ExchangeDC_' + ItemId + '" for="' + ExchangeClass + '">Exchange</label>' +
  1810. '</div>' +
  1811. ' </div>';
  1812. }
  1813. }
  1814. let IsMultipleUOMs = data.IsMultipleUOMs;
  1815. let MultipleUOMs = data.MultipleUOMs;
  1816. if (IsMultipleUOMs) {
  1817. html += '<div id="div_MultipleUOMs_' + ItemId + '" class="div_MultipleUOMs floating-label-form-group-with-value col-sm-4" > ' +
  1818. '<label for= "lbl" id ="lbl_MultipleUOMs_' + ItemId + '"> UOM </label>';
  1819. html += '<select id="ddl_MultipleUOMs_' + ItemId + '" class="form-control type-control value-control dropdown_MultipleUOMs" placeholder="Select UOM" data-placeholder="Select UOM" data-label="UOM" data-isparent="false">';
  1820. if (MultipleUOMs.length > 0) {
  1821. html += '<option value="1"> ' + MultipleUOMs[0].DefaultUnitName + ' ( Default Unit ) </option>';
  1822. }
  1823. else {
  1824. html += '<option value="1"> -- Select -- </option>';
  1825. }
  1826. for (var i = 0; i < MultipleUOMs.length; i++) {
  1827. let UOM = MultipleUOMs[i];
  1828. let Conversion = UOM.DefaultSize + " " + UOM.DefaultUnitName + " = " + UOM.AlternateSize + " " + UOM.AlternateUnitName;
  1829. html += '<option value="' + MultipleUOMs[i].SchemaDetailId + '">' + MultipleUOMs[i].AlternateUnitName + ' ( ' + Conversion + ' ) </option>';
  1830. }
  1831. html += '</div> </select>';
  1832. html += '<p class="mt-10 text-warning ItemConversion_' + ItemId + '"> </p>';
  1833. }
  1834. html += '</div>' +
  1835. '</div>';
  1836. html += ' </div>';
  1837. html += '</li>';
  1838. return html;
  1839. }
  1840. getItemDesignWithTokens_PurchasePlan() {
  1841. let instance = this;
  1842. let html = "";
  1843. let InventoryType = instance._order.g_InventoryApplyType;
  1844. html = '<li id="{{ItemId}}" class="list-group-item variant-item variant-addeditem variant-addeditem-{{ItemId}} li no-border">' +
  1845. '<input type="hidden" class="hfOrder_ItemId" value="{{ItemId}}" />' +
  1846. '<input type="hidden" class="hfOrder_RefItemId" value="{{RefItemIds}}" />' +
  1847. '<input type="hidden" class="hfOrder_ItemName" value="{{ItemName}}" />' +
  1848. '<input type="hidden" class="hfOrder_ItemSKU" value="{{SKU}}" />';
  1849. let DivClass = 'col-sm-8';
  1850. let InventoryTypeDivClass = 'col-sm-4';
  1851. if (instance.g_IsEnablePacks && instance.g_IsEnablePieces) {
  1852. DivClass = 'col-sm-6';
  1853. InventoryTypeDivClass = 'col-sm-6';
  1854. }
  1855. html += ' <div class="row">' +
  1856. '<div class="ItemDetails ' + DivClass + '" id="ItemDetails">' +
  1857. '<a class="pull-left mt-20 {{faimg}}" style="cursor:pointer;height:100px; width:100px;"> <i class="fa fa-image orderItem font-40 ml-3"></i> </a>' +
  1858. '<a class="pull-left {{imgtag}}" style="cursor:pointer;height:80px; width:100px;"> <img class="avatar" style="width: 70px; height: 70px;" onerror="ReloadImage(event)" data-dynamic="1" src="{{imgurl}}"> </a>';
  1859. html += '<span id="EditROQ_{{ItemId}}" onclick="Bizgaze.Apps.Transact.Components.PurchasePlan.Instance().loadEditROQ({{ItemId}})"> <strong> Edit </strong><span> <i class="fa fa-pencil ml-5"> </i> </span> </span> <br/> <input type="checkbox" id="chk_PurPlanItem_{{ItemId}}" class="chk_PurPlanItem css-checkbox" {{IsDisabledCheckBox}} {{PurchasePlanChecked}}/>' +
  1860. '<span class="ml-10 pull-right text-danger tax-error"></span><span class="block text-sm ml-2 mouseHoverClass CartItemName" style="color: #5ba8fb;">{{ItemName}}</span> <br>';
  1861. html += '<span>SKU : {{SKU}}';
  1862. if (instance._order.g_IsAdmin == 1 || instance._order.g_IsShowAvailability == 1) {
  1863. html += ', </span> ';
  1864. }
  1865. let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  1866. let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters;
  1867. let BranchId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_branchid").Value);
  1868. if (InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs || InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces || InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.PacksAndPieces) {
  1869. if (instance._order.g_IsAdmin == 1 || instance._order.g_IsShowAvailability == 1) {
  1870. html += `<span class="ItemAvailability">Avail : {{AvailablePacks}} / {{AvailablePieces}} ({{AvailableQuantity}})` + ` Pur PO: <a onclick='var filter = []; filter.push({"Key" : "estimateid", "Value": "{{EstimateId}}", ExpOp: 1}, {"Key" : "itemid", "Value": "{{ItemId}}", ExpOp: 1}, {"Key" : "ordertypeid", "Value": "2", ExpOp: 1}); Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_PurchasePlan_PendingDetails", null, filter, null);' style="color: #5ba8fb;text-decoration: underline;" class="PurPendingOrders"> {{InwardOrderPacks}} </a> Sales PO: <a onclick='var filter = []; filter.push({"Key" : "estimateid", "Value": "{{EstimateId}}", ExpOp: 1}, {"Key" : "itemid", "Value": "{{ItemId}}", ExpOp: 1}, {"Key" : "ordertypeid", "Value": "1", ExpOp: 1}); Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_PurchasePlan_PendingDetails", null, filter, null);' style="color: #5ba8fb;text-decoration: underline;" class="SalesPendingOrders">{{OutwardOrderPacks}}</a></span><span class="text-danger pull-right LessUnitPrice-error"></span><br/>`;
  1871. }
  1872. }
  1873. else if (InventoryType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1874. if (instance._order.g_IsAdmin == 1 || instance._order.g_IsShowAvailability == 1) {
  1875. html += '<span class="ItemAvailability">Avail : {{Packs}} Pur PO: <a href="javascript:;"style="color: #5ba8fb;text-decoration: underline;" class="PendingOrders">{{InwardOrderPacks}}</a> Sales PO: <a href="javascript:;"style="color: #5ba8fb;text-decoration: underline;" class="PendingOrders">{{OutwardOrderPacks}}</a></span><span class="text-danger pull-right LessUnitPrice-error"></span><br/>';
  1876. }
  1877. }
  1878. html += '<span class="block">Saftey Stock : {{MinPacks}} | Suggested : {{SuggestedPacks}} | Avg : {{AvgPacks}} </span>';
  1879. let Price_dataToggle = "";
  1880. if (instance._order.g_IsAdmin == 1 || instance._order.g_ShowPrice == 1) {
  1881. Price_dataToggle = `data-toggle="collapse"`;
  1882. }
  1883. html += '<br>';
  1884. html += '<span class="sp_PriceType font-12">Price : </span><span id="DiscountOpenBracket" class="hidden">(</span><a href="javascript:;" class="text-sm editItemPrice text-dark font-12" text-decoration: underline;"' + Price_dataToggle + 'data-target="#editItemPriceAccordion_{{ItemId}}"> {{ConfirmedUnitPrice}} </a> <span class="CompositePriceCalBreak"> </span> <span id="QuantityAndDiscountSpan font-12" class=""><span id="OrderQuantity_{{ItemId}}" class="OrderQuantity hidden">{{OrderQuantity}}</span><span id="multipliedvalue_{{ItemId}}" class="multipliedvalue hidden">{{multiplevalue}}</span></span>';
  1885. html += '<div id="LeverageErrorTxt" class="text-warning hidden font-10 ">Leverage % Exceeded</div>';
  1886. html += '</div>';
  1887. html += '<div id="InventoryTypesTextboxes" class="InventoryTypesTextboxes ' + InventoryTypeDivClass + '">';
  1888. html += instance.getInventoryDesignWithTokens_PurchasePlan();
  1889. html += '</div>';
  1890. html += '<div class="row collapse card py-2 mt-2 mb-0 " id="editItemPriceAccordion_{{ItemId}}">' +
  1891. '<div class="col-sm-12">' +
  1892. '<div class="input-group">' +
  1893. '<div class="col-sm-2">' +
  1894. '<div class="floating-label-form-group floating-label-form-group-with-value">';
  1895. html += '<label for="txt_editItemPrice">Unit price </label><input type="text" id="txt_editItemPrice" class="form-control floating-label-control txteditItemPrice" inputmode="numeric" value="{{ConfirmedUnitPrice}}" data-isdynamic="false" placeholder="Unit Price" data-placeholder="Enter Unit Price" data-label="Unit Price" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" min="0"></div>';
  1896. html += '</div>' +
  1897. '<div class="col-sm-2">' +
  1898. '<div class="floating-label-form-group discountFloatLabels floating-label-form-group-with-value">' +
  1899. '<label>Discount</label>' +
  1900. '<div class="input-group">' +
  1901. '<input type="text" id="Ord_txtdiscount" placeholder="Discount" inputmode="numeric" data-isdynamic="false" onpaste = "return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().validateFloatKeyPress(this,event)" data-placeholder="0.00" data-label="Discount" class="form-control ord_txtaddldiscount floating-label-control" value="{{Discount}}" {{offerDiscountClass}}>' +
  1902. '<div class="input-group-btn">' +
  1903. '<select class="btnOrder_DiscType mt-10 border-blue"><option value="2">Val</option><option value="1">%</option></select>' +
  1904. '</div>' +
  1905. '</div>' +
  1906. '</div>' +
  1907. '</div>' +
  1908. '<div class="col-sm-2">' +
  1909. '<div class="floating-label-form-group descriptionFloatLabels">' +
  1910. '<label>Description</label>' +
  1911. '<input type="text" id="txt_Description" class="form-control floating-label-control " data-isdynamic="false" placeholder="Description" data-placeholder="Description" data-label="Description">' +
  1912. '</div>' +
  1913. '</div>';
  1914. html += '</div>' +
  1915. ' </div>' +
  1916. ' </div>';
  1917. html += '</li>';
  1918. return html;
  1919. }
  1920. getManualUOMDesign(Itm) {
  1921. let html = `<input type="text" id="txt_ManualConversionQty" class="form-control floating-label-control col-sm-2" inputmode="numeric" onpaste="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" oninput="return Bizgaze.Apps.Transact.Controls.OrderItems.Instance().isNumberKey(event)" data-isdynamic="false" placeholder="" data-placeholder="" data-label="" value="` + Itm.ConversionQuantity + `" style="display: inline">
  1922. <select id="ddl_ManualUOMs_` + Itm.ItemId + `" class="type-control value-control dropdown_ManualUOMs" placeholder="Select UOM" data-placeholder="Select UOM" data-label="UOM" data-isparent="false" style="display: inline">`;
  1923. for (let i = 0; i < Itm.UOMs.length; i++) {
  1924. let Selected = "";
  1925. if (Itm.UOMs[i].UnitId == Itm.UOMSchemaId) {
  1926. Selected = "selected";
  1927. }
  1928. html += `<option value="` + Itm.UOMs[i].UnitId + `" ` + Selected + `>` + Itm.UOMs[i].UnitName + `</option>`;
  1929. }
  1930. html += `</select>`;
  1931. return html;
  1932. }
  1933. bindManualUOMData(elem, Itm, AmountWithDiscount) {
  1934. let instance = this;
  1935. $("#" + instance.g_VisibleContainerId).find(elem).find(".ManualUOM_" + Itm.ItemId).removeClass("hidden");
  1936. $("#" + instance.g_VisibleContainerId).find(elem).find(".ManualUOM_RowTotal").removeClass("hidden").text(" = " + AmountWithDiscount);
  1937. $("#" + instance.g_VisibleContainerId).find(elem).find("#txt_ManualConversionQty").val(Itm.ConversionQuantity);
  1938. $("#" + instance.g_VisibleContainerId).find(elem).find(".dropdown_ManualUOMs").val(Itm.SelectedUnitId);
  1939. }
  1940. updateItemsDesign(elem, evnt, IsCart = false, IsFocItem = false) {
  1941. debugger;
  1942. let instance = this;
  1943. if (elem.length != 0) {
  1944. let ItemId = $("#" + instance.g_VisibleContainerId).find(elem).find(".hfOrder_ItemId").val();
  1945. let RefItemIds = $("#" + instance.g_VisibleContainerId).find(elem).find(".hfOrder_RefItemId").val();
  1946. let CartItem_Index = -1;
  1947. if (IsFocItem) {
  1948. CartItem_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds == RefItemIds);
  1949. }
  1950. else {
  1951. CartItem_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds == "");
  1952. }
  1953. let Itm = instance.g_CartItems_New[CartItem_Index];
  1954. if (Itm == undefined) {
  1955. return false;
  1956. }
  1957. Itm.UnitPrice = Math.abs(Itm.UnitPrice);
  1958. Itm.UnitPriceWithOutTax = Math.abs(Itm.UnitPriceWithOutTax);
  1959. let UnitPrice = Itm.UnitPrice;
  1960. let UnitName = Itm.UnitName;
  1961. let pricelabel = "Price";
  1962. if (instance._order.g_IsPointsOrder) {
  1963. pricelabel = "Points";
  1964. }
  1965. if (instance.g_IsEnablePiecePrice)
  1966. pricelabel = "Piece Price";
  1967. if (instance.g_IsEnableCompositePrice) {
  1968. pricelabel = "Comp. Price";
  1969. }
  1970. if (instance.g_IsEnableCompositePiecePrice) {
  1971. pricelabel = "Comp. Piece Price";
  1972. }
  1973. $("#" + instance.g_VisibleContainerId).find(".sp_PriceType").text(pricelabel + " : ");
  1974. $("#" + instance.g_VisibleContainerId).find(".sp_PriceType").addClass("font-12");
  1975. let Cond = $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").is(":visible") || evnt == "BindItemList" || evnt == "FromWidget_FocItem" || evnt == "EditOrderItem" || evnt == "FromWidget" || evnt == "AddFocItem_IsOfferDiscountApplied" || evnt == "EditFocItem_IsOfferDiscountApplied" || evnt == "DeleteCartItem";
  1976. if (IsCart) {
  1977. Cond = !$("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").is(":visible") || evnt == "EditFocItem" || evnt == "AddFocItem_IsOfferDiscountApplied" || evnt == "EditFocItem_IsOfferDiscountApplied" || instance._order.g_IsSC_to_PC;
  1978. }
  1979. if (Cond) {
  1980. let Cartons = Itm.Quantity;
  1981. if (instance._order.g_InventoryApplyType != Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  1982. Cartons = Itm.Packs;
  1983. }
  1984. $("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemCount").val(Cartons);
  1985. $("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemPieceCount").val(Itm.Pieces);
  1986. $("#" + instance.g_VisibleContainerId).find(elem).find("#txt_editItemPrice").val(Itm.UnitPriceWithOutTax);
  1987. $("#" + instance.g_VisibleContainerId).find(elem).find(".btnOrder_DiscType").val(Itm.DiscountType);
  1988. let Discount = Itm.DiscountValue == 0 ? Itm.DiscountPercent : Itm.DiscountValue;
  1989. if (Discount == 0) {
  1990. $("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").val("");
  1991. }
  1992. else {
  1993. $("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").val(Discount);
  1994. }
  1995. }
  1996. if (Itm.Description != "" && Itm.Description != null) {
  1997. if (instance.g_FromWidgetEditOrderItemId > 0) {
  1998. $("#" + instance.g_VisibleContainerId).find("#txt_Description").val(Itm.Description);
  1999. }
  2000. else {
  2001. $("#" + instance.g_VisibleContainerId).find(elem).find("#txt_Description").val(Itm.Description);
  2002. }
  2003. $("#" + instance.g_VisibleContainerId).find(elem).find(".descriptionFloatLabels").addClass("floating-label-form-group-with-value");
  2004. }
  2005. if (Itm.Packs > 0) {
  2006. $("#" + instance.g_VisibleContainerId).find(elem).find(".defaultSelectedCartons").addClass("floating-label-form-group-with-value");
  2007. }
  2008. if (Itm.Pieces > 0) {
  2009. $("#" + instance.g_VisibleContainerId).find(elem).find(".defaultSelectedPieces").addClass("floating-label-form-group-with-value");
  2010. }
  2011. $("#" + instance.g_VisibleContainerId).find(elem).find(".CompositePriceCalBreak").html('');
  2012. if (Itm.ExchangeDC) {
  2013. $("#" + instance.g_VisibleContainerId).find(elem).find(".chkItem_ExchangeDC").prop("checked", true);
  2014. }
  2015. else {
  2016. $("#" + instance.g_VisibleContainerId).find(elem).find(".chkItem_ExchangeDC").prop("checked", false);
  2017. }
  2018. let ItemIndex = $("#" + instance.g_VisibleContainerId).find(elem).attr("class").toString().indexOf("variant-addeditem-" + Itm.ItemId);
  2019. if ((Itm.IsOfferAvailable && Itm.IsOfferDiscountApplied && IsCart && ItemIndex == -1 && !instance._order.g_IsManageOfferDiscount) || (Itm.ExchangeDC)) {
  2020. $("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").attr("disabled", "disabled").css("cursor", "not-allowed");
  2021. $("#" + instance.g_VisibleContainerId).find(elem).find(".btnOrder_DiscType").attr("disabled", "disabled").css("cursor", "not-allowed");
  2022. }
  2023. else {
  2024. $("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").removeAttr("disabled").removeAttr("style");
  2025. $("#" + instance.g_VisibleContainerId).find(elem).find(".btnOrder_DiscType").removeAttr("disabled").removeAttr("style");
  2026. }
  2027. if (Itm.IsMultipleUOMs) {
  2028. $("#" + instance.g_VisibleContainerId).find(elem).find("#ddl_MultipleUOMs_" + ItemId).val(Itm.SelectedUnitId);
  2029. if (Itm.SelectedUnitId != 1 && Itm.SelectedUnitId != 0) {
  2030. let UOM = Itm.MultipleUOMs.find(x => x.SchemaDetailId == Itm.SelectedUnitId);
  2031. let Conversion = UOM.DefaultSize + " " + UOM.DefaultUnitName + " = " + UOM.AlternateSize + " " + UOM.AlternateUnitName;
  2032. $("#" + instance.g_VisibleContainerId).find(".ItemConversion_" + Itm.ItemId).text(Conversion);
  2033. UnitName = Itm.SelectedUnitName;
  2034. }
  2035. else {
  2036. $("#" + instance.g_VisibleContainerId).find(".ItemConversion_" + Itm.ItemId).text("");
  2037. }
  2038. }
  2039. if (IsCart) {
  2040. if (Itm.ExchangeDC) {
  2041. UnitPrice = -Itm.UnitPrice;
  2042. let ItemName = Itm.ItemName + " (Exchange) ";
  2043. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId).find(".CartItemName").html(ItemName);
  2044. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId).find(".CartItemName").append("<input type='checkbox' class='divAfterTax' checked/> After Tax");
  2045. }
  2046. else {
  2047. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId).find(".CartItemName").html(Itm.ItemName);
  2048. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId).find(".CartItemName").find(".divAfterTax").remove();
  2049. }
  2050. }
  2051. if (instance.g_FromWidget) {
  2052. if (Itm.ExchangeDC) {
  2053. UnitPrice = -Itm.UnitPrice;
  2054. let ItemName = Itm.ItemName + " (Exchange) ";
  2055. $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId).find(".CartItemName").html(ItemName);
  2056. $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId).find(".CartItemName").append("<input type='checkbox' class='divAfterTax' checked/> After Tax");
  2057. }
  2058. else {
  2059. $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId).find(".CartItemName").html(Itm.ItemName);
  2060. $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId).find(".CartItemName").find(".divAfterTax").remove();
  2061. }
  2062. }
  2063. let _quantity = instance.roundOffIgnoreZerosAfterDecimal(Itm.BaseQty);
  2064. if (Itm.IsMultipleUOMs && Itm.ConversionQuantity > 0) {
  2065. _quantity = Itm.ConversionQuantity;
  2066. }
  2067. let AmountWithDiscount = instance.roundOffIgnoreZerosAfterDecimal(Number(Itm.AmountWithDiscount));
  2068. if (Itm.Packs == 0 && Itm.Pieces == 0) {
  2069. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text(Itm.UnitPrice).css({ 'text-decoration': 'underline', 'color': '#5ba8fb' });
  2070. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text("");
  2071. $("#" + instance.g_VisibleContainerId).find(elem).find(".chk_PurPlanItem").prop("checked", false).attr("disabled", "true");
  2072. }
  2073. else {
  2074. $("#" + instance.g_VisibleContainerId).find(elem).find(".chk_PurPlanItem").prop("checked", true).removeAttr("disabled");
  2075. if (Itm.DiscountValue > 0) {
  2076. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text("(" + Itm.UnitPrice).css({ 'text-decoration': 'underline', 'color': '#5ba8fb' });
  2077. if (Itm.IsManualUOM && instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales) {
  2078. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(" - " + Number(Itm.DiscountValue) + ") X ");
  2079. instance.bindManualUOMData(elem, Itm, AmountWithDiscount);
  2080. }
  2081. else {
  2082. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(" - " + Number(Itm.DiscountValue) + ") X " + _quantity + '(' + UnitName + ')' + " = " + AmountWithDiscount);
  2083. }
  2084. $("#" + instance.g_VisibleContainerId).find(elem).find(".discountFloatLabels").addClass("floating-label-form-group-with-value");
  2085. }
  2086. else if (Itm.DiscountPercent > 0) {
  2087. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text("(" + Itm.UnitPrice).css({ 'text-decoration': 'underline', 'color': '#5ba8fb' });
  2088. if (Itm.IsManualUOM && instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales) {
  2089. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(" - " + Number(Itm.DiscountPercent) + "%) X ");
  2090. instance.bindManualUOMData(elem, Itm, AmountWithDiscount);
  2091. }
  2092. else {
  2093. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(" - " + Number(Itm.DiscountPercent) + "%) X " + _quantity + '(' + UnitName + ')' + " = " + AmountWithDiscount);
  2094. }
  2095. $("#" + instance.g_VisibleContainerId).find(elem).find(".discountFloatLabels").addClass("floating-label-form-group-with-value");
  2096. }
  2097. else {
  2098. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text(Number(UnitPrice)).css({
  2099. 'text-decoration': 'underline', 'color': '#5ba8fb'
  2100. });
  2101. if (Itm.IsManualUOM && instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales) {
  2102. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(" X ");
  2103. instance.bindManualUOMData(elem, Itm, AmountWithDiscount);
  2104. }
  2105. else {
  2106. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(" X " + _quantity + '(' + UnitName + ')' + " = " + AmountWithDiscount);
  2107. }
  2108. $("#" + instance.g_VisibleContainerId).find(elem).find(".discountFloatLabels").removeClass("floating-label-form-group-with-value");
  2109. }
  2110. }
  2111. if (Itm.IsFocItem) {
  2112. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").removeAttr("style").removeAttr("data-toggle").removeAttr("data-collapse").attr("disabled", "true").css("cursor", "not-allowed");
  2113. $("#" + instance.g_VisibleContainerId).find(elem).find(".focBadge").removeClass("hidden");
  2114. $("#" + instance.g_VisibleContainerId).find(elem).find("#FocBadgeSKU").text(Itm.RefItemSKUs);
  2115. }
  2116. $("#" + instance.g_VisibleContainerId).find(elem).find("#DiscountOpenBracket").addClass("hidden");
  2117. instance.getPriceTypeValues(ItemId, Itm.Packs, Itm.Pieces);
  2118. let PiecePrice = instance.roundOffIgnoreZerosAfterDecimal(Itm.PiecePrice);
  2119. let CompositePrice = instance.roundOffIgnoreZerosAfterDecimal(Itm.CompositePrice);
  2120. let CompositePiecePrice = instance.roundOffIgnoreZerosAfterDecimal(Itm.CompositePiecePrice);
  2121. if (instance.g_IsEnablePiecePrice) {
  2122. let TotalPieces = (Itm.Packs * Itm.PackCount) + Itm.Pieces;
  2123. if (Itm.DiscountValue == 0 && Itm.DiscountPercent == 0) {
  2124. let RowTotal = PiecePrice * TotalPieces;
  2125. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text(PiecePrice);
  2126. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' X ' + TotalPieces + ' Pieces = ' + RowTotal);
  2127. }
  2128. else if (Itm.DiscountValue > 0) {
  2129. let DiscountAmount = Itm.DiscountValue * Itm.PackSize;
  2130. let RowTotal = (PiecePrice - DiscountAmount) * TotalPieces;
  2131. $("#" + instance.g_VisibleContainerId).find(elem).find("#DiscountOpenBracket").removeClass("hidden").text('(');
  2132. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text(PiecePrice);
  2133. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' - ' + DiscountAmount + ') X ' + TotalPieces + ' Pieces = ' + RowTotal);
  2134. }
  2135. else if (Itm.DiscountPercent > 0) {
  2136. let DiscountAmount = (PiecePrice * Itm.DiscountPercent) / 100;
  2137. let RowTotal = (PiecePrice - DiscountAmount) * TotalPieces;
  2138. $("#" + instance.g_VisibleContainerId).find(elem).find("#DiscountOpenBracket").removeClass("hidden");
  2139. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text(PiecePrice);
  2140. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' - ' + Itm.DiscountPercent + '%) X ' + TotalPieces + ' Pieces = ' + RowTotal);
  2141. }
  2142. }
  2143. if (instance.g_IsEnableCompositePrice) {
  2144. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text(CompositePrice);
  2145. if (Itm.DiscountValue == 0 && Itm.DiscountPercent == 0) {
  2146. let RowTotal = instance.roundOffIgnoreZerosAfterDecimal(CompositePrice * _quantity);
  2147. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' X ' + _quantity + ' ' + UnitName + ' = ' + RowTotal);
  2148. }
  2149. else if (Itm.DiscountValue > 0) {
  2150. let DiscountAmount = Itm.DiscountValue * _quantity;
  2151. let RowTotal = (Itm.UnitPriceWithOutTax * _quantity) - DiscountAmount;
  2152. let AmountWithTax = instance.getAmountWithTax(Itm.ItemId, RowTotal).split('|');
  2153. let RowTotalWithTax = instance.roundOffIgnoreZerosAfterDecimal(AmountWithTax[0]);
  2154. let RowTax = AmountWithTax[1];
  2155. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text('(' + Itm.UnitPriceWithOutTax);
  2156. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' - ' + Itm.DiscountValue + ') X ' + _quantity + ' ' + UnitName + ' + (' + RowTax + ') = ' + RowTotalWithTax);
  2157. }
  2158. else if (Itm.DiscountPercent > 0) {
  2159. let Amount = (Itm.BaseQty * Itm.UnitPriceWithOutTax);
  2160. let DiscountAmount = (Amount * Itm.DiscountPercent) / 100;
  2161. let RowTotal = (Itm.UnitPriceWithOutTax * _quantity) - DiscountAmount;
  2162. let AmountWithTax = instance.getAmountWithTax(Itm.ItemId, RowTotal).split('|');
  2163. let RowTotalWithTax = instance.roundOffIgnoreZerosAfterDecimal(AmountWithTax[0]);
  2164. let RowTax = AmountWithTax[1];
  2165. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text('(' + Itm.UnitPriceWithOutTax);
  2166. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' - ' + Itm.DiscountPercent + '%) X ' + _quantity + ' ' + UnitName + ' + (' + RowTax + ') = ' + RowTotalWithTax);
  2167. }
  2168. }
  2169. if (instance.g_IsEnableCompositePiecePrice) {
  2170. let CompositePiecePrice = instance.roundOffIgnoreZerosAfterDecimal(Itm.CompositePiecePrice);
  2171. let PiecePrice = instance.roundOffIgnoreZerosAfterDecimal(Itm.PiecePrice);
  2172. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text(CompositePiecePrice);
  2173. if (Itm.DiscountValue == 0 && Itm.DiscountPercent == 0) {
  2174. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' (' + _quantity + ' ' + UnitName + ')');
  2175. }
  2176. else if (Itm.DiscountValue > 0) {
  2177. let DiscountAmount = Itm.DiscountValue * _quantity;
  2178. let RowTotal = PiecePrice - DiscountAmount;
  2179. let AmountWithTax = instance.getAmountWithTax(Itm.ItemId, RowTotal).split('|');
  2180. let RowTotalWithTax = instance.roundOffIgnoreZerosAfterDecimal(AmountWithTax[0]);
  2181. let RowTax = AmountWithTax[1];
  2182. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text('(' + Itm.UnitPriceWithOutTax);
  2183. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' - ' + Itm.DiscountValue + ') X ' + _quantity + ' ' + UnitName + ' + (' + RowTax + ') = ' + RowTotalWithTax);
  2184. }
  2185. else if (Itm.DiscountPercent > 0) {
  2186. let Amount = (Itm.BaseQty * Itm.UnitPriceWithOutTax);
  2187. let DiscountAmount = (Amount * Itm.DiscountPercent) / 100;
  2188. let RowTotal = PiecePrice - DiscountAmount;
  2189. let AmountWithTax = instance.getAmountWithTax(Itm.ItemId, RowTotal).split('|');
  2190. let RowTotalWithTax = instance.roundOffIgnoreZerosAfterDecimal(AmountWithTax[0]);
  2191. let RowTax = AmountWithTax[1];
  2192. $("#" + instance.g_VisibleContainerId).find(elem).find(".editItemPrice").text('(' + Itm.UnitPriceWithOutTax);
  2193. $("#" + instance.g_VisibleContainerId).find(elem).find("#QuantityAndDiscountSpan").text(' - ' + Itm.DiscountPercent + '%) X ' + _quantity + ' ' + UnitName + ' + (' + RowTax + ') = ' + RowTotalWithTax);
  2194. }
  2195. }
  2196. if (evnt == "RefreshAllItems_InventoryClickEvents" || evnt == "FromWidget") {
  2197. let html = instance.getInventoryDesign(ItemId, IsCart, 0, Itm.RefItemIds);
  2198. $("#" + instance.g_VisibleContainerId).find(elem).find("#InventoryTypesTextboxes").html(html);
  2199. instance.allItemEvents(elem);
  2200. }
  2201. if (instance._order.g_ExpandItemSettings && (instance._order.g_IsAdmin == 1 || instance._order.g_ShowPrice == 1)) {
  2202. $("#editItemPriceAccordion_" + ItemId).removeClass("collapse");
  2203. }
  2204. else {
  2205. $("#editItemPriceAccordion_" + ItemId).addClass("collapse");
  2206. }
  2207. instance.checkErrors();
  2208. instance.checkLoyalityErrors(elem);
  2209. }
  2210. }
  2211. updateItemsAvailability(res) {
  2212. let instance = this;
  2213. let Items = $("#" + instance.g_VisibleContainerId).find(".variant-list").find("li");
  2214. for (let i = 0; i < Items.length; i++) {
  2215. let elem = Items[i];
  2216. let ItemId = $("#" + instance.g_VisibleContainerId).find(elem).find(".hfOrder_ItemId").val();
  2217. if (ItemId > 0) {
  2218. let data = res.find(x => x.ItemId == ItemId);
  2219. $("#" + instance.g_VisibleContainerId).find(elem).find(".ItemAvailability").text('Avail : ' + data.AvailablePacks + ' / ' + data.AvailablePieces + ' (' + data.AvailableQuantity + ')');
  2220. }
  2221. }
  2222. let CartItems = $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").find("li");
  2223. for (let c = 0; c < CartItems.length; c++) {
  2224. let elem = CartItems[c];
  2225. let ItemId = $("#" + instance.g_VisibleContainerId).find(elem).find(".hfOrder_ItemId").val();
  2226. if (ItemId > 0) {
  2227. let data = res.find(x => x.ItemId == ItemId);
  2228. $("#" + instance.g_VisibleContainerId).find(elem).find(".CartAvailability").text('Avail : ' + data.AvailablePacks + ' / ' + data.AvailablePieces + ' (' + data.AvailableQuantity + ')');
  2229. }
  2230. }
  2231. }
  2232. allItemEvents(elem) {
  2233. let instance = this;
  2234. if (!instance.g_PacksFocus && !instance.g_PiecesFocus) {
  2235. if (instance.g_IsEnablePacks) {
  2236. instance.g_PacksFocus = true;
  2237. }
  2238. else if (instance.g_IsEnablePieces) {
  2239. instance.g_PiecesFocus = false;
  2240. }
  2241. }
  2242. let timer;
  2243. if (instance._order.g_IsSC_to_PC && !instance._order.g_IsFromPurchaseIndent) {
  2244. $("#" + instance.g_VisibleContainerId).find(elem).find(".quantity-plus").addClass("disabled");
  2245. $("#" + instance.g_VisibleContainerId).find(elem).find("#div_Cartons").find(".input-group-append").css("cursor", "not-allowed");
  2246. }
  2247. $("#" + instance.g_VisibleContainerId).find(".mouseHoverClass").hover(function () {
  2248. $("#" + instance.g_VisibleContainerId).find(this).closest(".variant-item").find('.mouseHoverClass').css({ 'font-weight': '' });
  2249. }, function () { $("#" + instance.g_VisibleContainerId).find(this).closest(".variant-item").find('.mouseHoverClass').css({ 'font-weight': '' }); });
  2250. $("#" + instance.g_VisibleContainerId).find(elem).find(".chk_PurPlanItem").unbind().click(function () {
  2251. let element = elem;
  2252. let ItemId = element.find(".hfOrder_ItemId").val();
  2253. if ($("#" + instance.g_VisibleContainerId).find(this).is(':checked')) {
  2254. instance.updateItemsArray(element, "PurPlan");
  2255. }
  2256. else {
  2257. instance.deleteCartItems(ItemId);
  2258. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").find(".cartitem-" + ItemId).remove();
  2259. }
  2260. });
  2261. $("#" + instance.g_VisibleContainerId).find(".editCartItemQuantity").unbind().click(function () {
  2262. let element = elem;
  2263. element.find("._editCartItemQuantity").toggleClass("hidden");
  2264. element.find(".editCartItemQuantity").toggleClass("hidden");
  2265. element.find(".CartAvailability").toggleClass("hidden");
  2266. });
  2267. $("#" + instance.g_VisibleContainerId).find(elem).find('.txtOrder_ItemCount').unbind().click(function () {
  2268. instance.g_PacksFocus = true;
  2269. instance.g_PiecesFocus = false;
  2270. });
  2271. $("#" + instance.g_VisibleContainerId).find(elem).find('.txtOrder_ItemPieceCount').unbind().click(function () {
  2272. instance.g_PiecesFocus = true;
  2273. instance.g_PacksFocus = false;
  2274. });
  2275. $("#" + instance.g_VisibleContainerId).find(elem).find(".txteditItemPrice").unbind().keyup(function () {
  2276. clearTimeout(timer);
  2277. timer = setTimeout(function () {
  2278. let element = elem;
  2279. instance.updateItemsArray(element, "UnitPrice");
  2280. }, 300);
  2281. });
  2282. $("#" + instance.g_VisibleContainerId).find(elem).find("#txt_ManualConversionQty").unbind().keyup(function () {
  2283. clearTimeout(timer);
  2284. timer = setTimeout(function () {
  2285. let element = elem;
  2286. instance.updateItemsArray(element, "ManualConversionQty");
  2287. }, 300);
  2288. });
  2289. $("#" + instance.g_VisibleContainerId).find(elem).find(".dropdown_ManualUOMs").unbind().change(function () {
  2290. let element = elem;
  2291. let ItemId = element.find(".hfOrder_ItemId").val();
  2292. let ItmIndex = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId);
  2293. if (ItmIndex != -1) {
  2294. let SelectedUnitId = Number($("#" + instance.g_VisibleContainerId).find(elem).find(".dropdown_ManualUOMs").val());
  2295. let SelectedUnitName = $("#" + instance.g_VisibleContainerId).find(elem).find(".dropdown_ManualUOMs option:selected").text();
  2296. instance.g_CartItems_New[ItmIndex].SelectedUnitId = SelectedUnitId;
  2297. instance.g_CartItems_New[ItmIndex].SelectedUnitName = SelectedUnitName;
  2298. $("#ulOrder_Cart").find("#ddl_ManualUOMs_" + ItemId).val(SelectedUnitId);
  2299. }
  2300. });
  2301. $("#" + instance.g_VisibleContainerId).find(elem).find(".quantity-plus").unbind().click(function () {
  2302. let element = elem;
  2303. let Packs = Number(element.find(".txtOrder_ItemCount").val());
  2304. let Pieces = 0;
  2305. if (instance.g_IsEnablePieces) {
  2306. Pieces = Number(element.find(".txtOrder_ItemPieceCount").val());
  2307. }
  2308. if (Packs == 0 && Pieces > 0) {
  2309. instance.g_PacksFocus = false;
  2310. instance.g_PiecesFocus = true;
  2311. }
  2312. if (instance.g_PacksFocus) {
  2313. if (element.find("#txt_Pieces").val() == 0) {
  2314. element.find('.divOrders_ItemPieceCount').removeClass('floating-label-form-group-with-value');
  2315. }
  2316. element.find('.divOrders_ItemCount').addClass('floating-label-form-group-with-value');
  2317. let Packs = Number(element.find(".txtOrder_ItemCount").val());
  2318. let incVal = instance.getIncrementValue(Packs);
  2319. let val = instance.roundOffIgnoreZerosAfterDecimal(Packs + incVal);
  2320. element.find(".txtOrder_ItemCount").val(val);
  2321. }
  2322. if (instance.g_PiecesFocus) {
  2323. element.find('.divOrders_ItemPieceCount').addClass('floating-label-form-group-with-value');
  2324. let Pieces = Number(element.find(".txtOrder_ItemPieceCount").val());
  2325. let incVal = instance.getIncrementValue(Pieces);
  2326. let val = instance.roundOffIgnoreZerosAfterDecimal(Pieces + incVal);
  2327. element.find(".txtOrder_ItemPieceCount").val(val);
  2328. }
  2329. instance.updateItemsArray(element, "Plus");
  2330. });
  2331. $("#" + instance.g_VisibleContainerId).find(elem).find(".quantity-minus").unbind().click(function () {
  2332. let element = elem;
  2333. let ItemId = element.find(".hfOrder_ItemId").val();
  2334. let Packs = Number(element.find(".txtOrder_ItemCount").val());
  2335. let Pieces = Number(element.find(".txtOrder_ItemPieceCount").val());
  2336. if (Packs == 0 && Pieces > 0) {
  2337. instance.g_PacksFocus = false;
  2338. instance.g_PiecesFocus = true;
  2339. }
  2340. if (instance.g_PacksFocus) {
  2341. if (element.find("#txt_Pieces").val() == 0) {
  2342. element.find('.divOrders_ItemPieceCount').removeClass('floating-label-form-group-with-value');
  2343. }
  2344. element.find('.divOrders_ItemCount').addClass('floating-label-form-group-with-value');
  2345. let incVal = instance.getIncrementValue(Packs);
  2346. if (Packs > 0) {
  2347. let val = instance.roundOffIgnoreZerosAfterDecimal(Packs - incVal);
  2348. element.find(".txtOrder_ItemCount").val(val);
  2349. }
  2350. else if (Packs == 0 && Pieces > 0) {
  2351. element.find(".txtOrder_ItemCount").val(instance.roundOffIgnoreZerosAfterDecimal(Packs));
  2352. }
  2353. else {
  2354. element.find('.divOrders_ItemCount').removeClass('floating-label-form-group-with-value');
  2355. instance.deleteCartItems(ItemId);
  2356. return false;
  2357. }
  2358. }
  2359. if (instance.g_PiecesFocus) {
  2360. element.find('.divOrders_ItemPieceCount').addClass('floating-label-form-group-with-value');
  2361. let Pieces = Number(element.find(".txtOrder_ItemPieceCount").val());
  2362. let incVal = instance.getIncrementValue(Pieces);
  2363. if (Pieces > 0) {
  2364. let val = instance.roundOffIgnoreZerosAfterDecimal(Pieces - incVal);
  2365. element.find(".txtOrder_ItemPieceCount").val(val);
  2366. }
  2367. else if (Pieces == 0 && Packs > 0) {
  2368. element.find(".txtOrder_ItemPieceCount").val(instance.roundOffIgnoreZerosAfterDecimal(Pieces));
  2369. }
  2370. else {
  2371. element.find('.divOrders_ItemPieceCount').removeClass('floating-label-form-group-with-value');
  2372. instance.deleteCartItems(ItemId);
  2373. return false;
  2374. }
  2375. }
  2376. instance.updateItemsArray(element, "Minus");
  2377. });
  2378. $("#" + instance.g_VisibleContainerId).find(elem).find('.chkItem_ExchangeDC').unbind().change(function () {
  2379. let element = elem;
  2380. let ItemId = element.find(".hfOrder_ItemId").val();
  2381. if (element.find('.chkItem_ExchangeDC').prop("checked")) {
  2382. element.find('#Ord_txtdiscount').val('').prop("disabled", true).css("cursor", "not-allowed");
  2383. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId).find("#Ord_txtdiscount").val('').prop("disabled", true).css("cursor", "not-allowed");
  2384. }
  2385. else {
  2386. element.find('#Ord_txtdiscount').prop("disabled", false).css("cursor", "auto");
  2387. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId).find('#Ord_txtdiscount').prop("disabled", false).css("cursor", "auto");
  2388. }
  2389. instance.updateItemsArray(element, "Exchange");
  2390. });
  2391. $("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemCount").keyup(function () {
  2392. clearTimeout(timer);
  2393. timer = setTimeout(function () {
  2394. instance.updateItemsArray(elem, "Packs");
  2395. }, 300);
  2396. });
  2397. $("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemPieceCount").keyup(function () {
  2398. clearTimeout(timer);
  2399. timer = setTimeout(function () {
  2400. instance.updateItemsArray(elem, "Pieces");
  2401. }, 300);
  2402. });
  2403. $("#" + instance.g_VisibleContainerId).find(elem).find(".btnOrder_DiscType").unbind().change(function () {
  2404. instance.updateItemsArray(elem, "DiscountType");
  2405. });
  2406. $("#" + instance.g_VisibleContainerId).find(elem).find("#Ord_txtdiscount").unbind().keyup(function () {
  2407. clearTimeout(timer);
  2408. timer = setTimeout(function () {
  2409. instance.updateItemsArray(elem, "Discount");
  2410. }, 300);
  2411. });
  2412. let DescriptionElem = $("#" + instance.g_VisibleContainerId).find(elem).find("#txt_Description");
  2413. if (instance.g_FromWidgetEditOrderItemId > 0) {
  2414. DescriptionElem = $("#" + instance.g_VisibleContainerId).find("#txt_Description");
  2415. }
  2416. $(DescriptionElem).unbind().keyup(function () {
  2417. clearTimeout(timer);
  2418. timer = setTimeout(function () {
  2419. let ItemId = elem.find(".hfOrder_ItemId").val();
  2420. let CartItem = instance.g_CartItems_New.find(x => x.ItemId == ItemId && x.RefItemIds == "");
  2421. if (CartItem != undefined) {
  2422. if (instance.g_FromWidgetEditOrderItemId > 0) {
  2423. CartItem.Description = $("#txt_Description").val().toString();
  2424. }
  2425. else {
  2426. CartItem.Description = elem.find("#txt_Description").val().toString();
  2427. }
  2428. }
  2429. }, 300);
  2430. });
  2431. $("#" + instance.g_VisibleContainerId).find(elem).find(".delete").unbind().click(function () {
  2432. let FromWidget = false;
  2433. if (instance.g_CartItems_New.length <= 10) {
  2434. $("#" + instance.g_VisibleContainerId).find(".CartItemFindTxt").addClass('hidden');
  2435. }
  2436. let message = "Do you really want to delete this item";
  2437. if (instance.g_CartItems_New.length == 1)
  2438. message = "Your cart is going to empty.";
  2439. let itemid = $("#" + instance.g_VisibleContainerId).find(this).parents(".cartitem").find(".hfOrder_ItemId").val();
  2440. if (itemid == undefined) {
  2441. itemid = $("#" + instance.g_VisibleContainerId).find(this).parents(".variant-addeditem").find(".hfOrder_ItemId").val();
  2442. }
  2443. if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length > 0) {
  2444. FromWidget = true;
  2445. }
  2446. bootbox.confirm({
  2447. message: message,
  2448. closeButton: false,
  2449. buttons: {
  2450. confirm: {
  2451. label: 'Yes',
  2452. className: 'btn-success'
  2453. },
  2454. cancel: {
  2455. label: 'No',
  2456. className: 'btn-danger'
  2457. }
  2458. },
  2459. callback: function (result) {
  2460. if (result) {
  2461. instance.deleteCartItems(itemid, FromWidget);
  2462. if (instance._order.g_IsPurchasePlanning)
  2463. $("#" + instance.g_VisibleContainerId).find("#chk_PurPlanItem_" + itemid).prop("checked", false);
  2464. }
  2465. }
  2466. });
  2467. });
  2468. $("#" + instance.g_VisibleContainerId).find(elem).find(".div_MultipleUOMs").change(function () {
  2469. instance.updateItemsArray(elem, "UOMChange");
  2470. });
  2471. }
  2472. readScanner(capturedValue, uniqueId) {
  2473. if (capturedValue != "" && capturedValue != null && capturedValue != undefined) {
  2474. $("#txt_SearchItem").val(capturedValue);
  2475. }
  2476. }
  2477. refreshAllItems(FromWidget = false, evnt) {
  2478. let instance = this;
  2479. for (let i = 0; i < instance.g_LoadedItems.length; i++) {
  2480. let Itm = instance.g_LoadedItems[i];
  2481. let elem = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + Itm.ItemId);
  2482. if (elem != undefined && elem.length > 0) {
  2483. instance.updateItemsArray(elem, "RefreshAllItems_" + evnt, FromWidget);
  2484. }
  2485. }
  2486. }
  2487. bindAllItemsQty(FromWidget = false, evnt) {
  2488. let instance = this;
  2489. for (let i = 0; i < instance.g_LoadedItems.length; i++) {
  2490. let Itm = instance.g_LoadedItems[i];
  2491. let elem = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + Itm.ItemId);
  2492. if (elem != undefined && elem.length > 0) {
  2493. let CartIndex = instance.g_CartItems_New.findIndex(x => x.ItemId == Itm.ItemId);
  2494. if (CartIndex != -1) {
  2495. let inventoryApplyType = instance._order.g_InventoryApplyType;
  2496. if (inventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  2497. elem.find("#txt_Cartons").val(instance.g_CartItems_New[CartIndex].Quantity);
  2498. elem.find("#txt_Pieces").val(0);
  2499. }
  2500. else if (inventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs) {
  2501. elem.find("#txt_Cartons").val(instance.g_CartItems_New[CartIndex].Packs);
  2502. elem.find("#txt_Pieces").val(instance.g_CartItems_New[CartIndex].Pieces);
  2503. }
  2504. else if (inventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.PacksAndPieces) {
  2505. elem.find("#txt_Cartons").val(instance.g_CartItems_New[CartIndex].Packs);
  2506. elem.find("#txt_Pieces").val(instance.g_CartItems_New[CartIndex].Pieces);
  2507. }
  2508. instance.updateItemsArray(elem, "RefreshAllItems_" + evnt, FromWidget, 0, instance.g_CartItems_New[CartIndex].Pieces);
  2509. }
  2510. else {
  2511. instance.updateItemsArray(elem, "RefreshAllItems_" + evnt, FromWidget);
  2512. }
  2513. }
  2514. }
  2515. }
  2516. showBOMItems(ItemId, ItemName, element) {
  2517. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFiles(["apps/transact/components/orders/itembomselection.js"], function () {
  2518. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(0, "", Bizgaze.Apps.Transact.Components.Orders.ItemBOMSelection.Instance(), function () {
  2519. Bizgaze.Apps.Transact.Components.Orders.ItemBOMSelection.Instance().LoadBOMItems(ItemId, ItemName);
  2520. }, Unibase.Platform.Helpers.Size.Large);
  2521. });
  2522. }
  2523. itemSettings(FromWidget = false) {
  2524. let instance = this;
  2525. let inventoryHtml = `<div class="row" id="div_chkpieces"><div class="col-sm-3 hidden divselectall"><div class="custom-control custom-checkbox divselectall checkbox-primary"><input type="checkbox" class="custom-control-input" id="chk_AllItems"><label class="custom-control-label" for="chk_AllItems">Select All</label></div></div><div class="col-sm-4 div_chk_Packs hidden"><div class="custom-control custom-checkbox divEnablePacks checkbox-primary"><input type="checkbox" class="custom-control-input" id="chk_Packs"><label class="custom-control-label" for="chk_Packs">Enable Packs</label></div></div><div class="col-sm-4 div_chk_Pieces hidden"><div class="custom-control custom-checkbox divEnablePieces checkbox-primary"><input type="checkbox" class="custom-control-input" id="chk_Pieces"><label class="custom-control-label" for="chk_Pieces">Enable Pieces</label></div></div><div class="col-sm-4 hidden div_chk_CompositePrice"><div class="custom-control custom-checkbox checkbox-primary"><input type="checkbox" class="custom-control-input" id="chk_CompositePrice"><label class="custom-control-label" for="chk_CompositePrice">Enable Composite Price</label></div></div><div class="col-sm-4 hidden div_chk_PiecePrice"><div class="custom-control custom-checkbox checkbox-primary"><input type="checkbox" class="custom-control-input" id="chk_PiecePrice"><label class="custom-control-label" for="chk_PiecePrice">Enable Piece Price</label></div></div></div><br />`;
  2526. if (instance._order.g_InventoryApplyType != Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity) {
  2527. inventoryHtml += `<div class="row mb-20 div_chk_Qty" id="div_chk_Qty">
  2528. <div class="col-sm-12">
  2529. <div class="custom-control custom-checkbox divEnableQty checkbox-primary pull-right col-sm-3">
  2530. <input type="checkbox" class="custom-control-input" id="chk_Qty">
  2531. <label class="custom-control-label" for="chk_Qty"> Quantity </label>
  2532. </div>
  2533. </div>
  2534. </div>`;
  2535. }
  2536. inventoryHtml += `<div class="d-none d-md-block"><div class="row div_titledetails font-weight-500 text-dark"><div class="col-sm-8 ItemDetails">Item Details</div><div class="col-sm-4 Inventory_Title InventoryTypesTextboxes text-center"> <div class="p-0"> <div class="row p-0"> <span id="spn_InventoryTitle" class="col-6">Cartons</span><span id="spn_picesTitle" class="col-6 pull-right hidden"> Pieces</span></div></div></div></div></div><div class="mt-2" id="div_ItemList"></div>`;
  2537. $("#" + instance.g_VisibleContainerId).find(".InventorySettings").html(inventoryHtml);
  2538. $("#" + instance.g_VisibleContainerId).find("#div_ItemList").html('<ul class="variant-list list-group" style="0px -21px"><li class="variant-item hidden"></li>');
  2539. if (!instance._order.g_IsSC_to_PC) {
  2540. instance.g_CartItems_New = [];
  2541. instance.g_SC_PC_CartItems = [];
  2542. instance.g_ItemsUnitPrice_New = [];
  2543. instance.g_SelectedItems = [];
  2544. instance.g_LoadedItems = [];
  2545. }
  2546. $("#" + instance.g_VisibleContainerId).find("#chk_AllItems").unbind().click(function () {
  2547. if ($("#" + instance.g_VisibleContainerId).find('#chk_AllItems').is(':checked')) {
  2548. instance.navigationHelper.showLoading();
  2549. $("#" + instance.g_VisibleContainerId).find(".variant-list").find(".chk_PurPlanItem").each(function () {
  2550. let element = $("#" + instance.g_VisibleContainerId).find(this).closest(".variant-item");
  2551. if (element.find("#txt_Cartons").val() != 0 && element.find("#txt_Cartons").val() != "") {
  2552. instance.updateItemsArray(element, "PurPlan_AllItems", false);
  2553. $("#" + instance.g_VisibleContainerId).find(element).find(".chk_PurPlanItem").prop("checked", true);
  2554. }
  2555. });
  2556. instance.navigationHelper.hideLoading();
  2557. instance.getPurchasePlanTotals(false, true);
  2558. }
  2559. else {
  2560. $("#" + instance.g_VisibleContainerId).find(".variant-list").find(".chk_PurPlanItem").prop("checked", false);
  2561. instance.g_CartItems_New = [];
  2562. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").find(".cartitem").remove();
  2563. $("#" + instance.g_VisibleContainerId).find("#OverallOrderQuantity").text("0");
  2564. $("#" + instance.g_VisibleContainerId).find("#totalOrderItems").text("0");
  2565. instance.getPurchasePlanTotals(false, true);
  2566. }
  2567. });
  2568. instance.inventoryTypeClickEvents(FromWidget);
  2569. instance.priceTypeClickEvents(FromWidget);
  2570. }
  2571. clearItemSearch() {
  2572. let instance = this;
  2573. $("#" + instance.g_VisibleContainerId).find(".search-clear-items").addClass("d-none");
  2574. $("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val("");
  2575. Bizgaze.Apps.Transact.Controls.OrderItems.Instance().loadItems("", false);
  2576. }
  2577. itemSettingsEvents() {
  2578. var instance = this;
  2579. let timer;
  2580. $("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").on('input', function () {
  2581. clearTimeout(timer);
  2582. timer = setTimeout(function () {
  2583. var checkvalue = $("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val();
  2584. let check = checkvalue.toString();
  2585. if (check.length != 0) {
  2586. $("#" + instance.g_VisibleContainerId).find(".search-clear-items").removeClass("d-none");
  2587. }
  2588. else {
  2589. $("#" + instance.g_VisibleContainerId).find(".search-clear-items").addClass("d-none");
  2590. }
  2591. instance.g_PageIndex = 0;
  2592. if (instance._order.g_IsPurchasePlanning)
  2593. instance.loadPurchasePlanItems($("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val());
  2594. else
  2595. instance.loadItems($("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val());
  2596. }, 1500);
  2597. });
  2598. $("#" + instance.g_VisibleContainerId).find("#ItemLoadType").change(function () {
  2599. $("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val('');
  2600. $("#" + instance.g_VisibleContainerId).find("#ItemLoadType option[value='0']").remove();
  2601. let type = $("#" + instance.g_VisibleContainerId).find("#ItemLoadType option:selected").text();
  2602. if (type != "Filter" && !Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_OnlyFilters) {
  2603. instance.g_IsFilterApplied = false;
  2604. instance.g_FilteredTags = '';
  2605. Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_TagArray = [];
  2606. Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_ClearingTags = "";
  2607. }
  2608. instance.g_PageIndex = 0;
  2609. if (instance._order.g_IsPurchasePlanning) {
  2610. instance.loadPurchasePlanItems('');
  2611. }
  2612. else {
  2613. if (type == "Filter") {
  2614. instance.navigationHelper.popup(0, '', Bizgaze.Apps.Transact.Components.OrderFilter.Instance(), null, Unibase.Platform.Helpers.Size.Medium);
  2615. }
  2616. else {
  2617. instance.loadItems(type);
  2618. }
  2619. }
  2620. });
  2621. $("#" + instance.g_VisibleContainerId).find(".ContinueShopping").unbind().click(function () {
  2622. instance.continueShopping();
  2623. });
  2624. }
  2625. inventoryTypeClickEvents(FromWidget) {
  2626. let instance = this;
  2627. $("#" + instance.g_VisibleContainerId).find('#chk_Pieces').click(function () {
  2628. if ($("#" + instance.g_VisibleContainerId).find('#chk_Pieces').is(':checked')) {
  2629. instance.g_IsEnablePieces = true;
  2630. }
  2631. else {
  2632. instance.g_IsEnablePieces = false;
  2633. instance.g_PacksFocus = true;
  2634. instance.g_PiecesFocus = false;
  2635. }
  2636. instance.refreshAllItems(FromWidget, "InventoryClickEvents");
  2637. });
  2638. $("#" + instance.g_VisibleContainerId).find('#chk_Packs').click(function () {
  2639. if ($("#" + instance.g_VisibleContainerId).find('#chk_Packs').is(':checked')) {
  2640. instance.g_IsEnablePacks = true;
  2641. }
  2642. else {
  2643. instance.g_IsEnablePacks = false;
  2644. instance.g_PacksFocus = false;
  2645. instance.g_PiecesFocus = true;
  2646. }
  2647. instance.refreshAllItems(FromWidget, "InventoryClickEvents");
  2648. });
  2649. $("#" + instance.g_VisibleContainerId).find('#chk_Qty').click(function () {
  2650. if ($("#" + instance.g_VisibleContainerId).find('#chk_Qty').is(':checked')) {
  2651. instance.g_IsEnablePacks = true;
  2652. instance.g_PacksFocus = true;
  2653. instance._order.g_InventoryApplyType = Bizgaze.Apps.Transact.Enums.InventoryApplyType.Quantity;
  2654. instance._order.setInventorySettings(instance._order.g_InventoryApplyType, false);
  2655. }
  2656. else {
  2657. instance._order.g_InventoryApplyType = instance._order.g_LobInventoryApplyType;
  2658. instance._order.setInventorySettings(instance._order.g_InventoryApplyType, false);
  2659. }
  2660. instance.bindAllItemsQty(FromWidget, "InventoryClickEvents");
  2661. });
  2662. }
  2663. setPriceType() {
  2664. var instance = this;
  2665. if (instance.g_IsEnablePiecePrice) {
  2666. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.PiecePrice;
  2667. }
  2668. else if (instance.g_IsEnableCompositePrice) {
  2669. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.CompositePrice;
  2670. }
  2671. else if (instance.g_IsEnableCompositePiecePrice) {
  2672. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.Both;
  2673. }
  2674. else {
  2675. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.None;
  2676. }
  2677. }
  2678. priceTypeClickEvents(FromWidget) {
  2679. let instance = this;
  2680. $("#" + instance.g_VisibleContainerId).find('#chk_PiecePrice').click(function () {
  2681. if ($("#" + instance.g_VisibleContainerId).find('#chk_PiecePrice').is(':checked')) {
  2682. if (instance.g_IsEnableCompositePrice) {
  2683. instance.g_IsEnableCompositePrice = false;
  2684. instance.g_IsEnablePiecePrice = false;
  2685. instance.g_IsEnableCompositePiecePrice = true;
  2686. }
  2687. else {
  2688. instance.g_IsEnablePiecePrice = true;
  2689. instance.g_IsEnableCompositePiecePrice = false;
  2690. instance.g_IsEnableCompositePrice = false;
  2691. }
  2692. }
  2693. else {
  2694. instance.g_IsEnablePiecePrice = false;
  2695. instance.g_IsEnableCompositePiecePrice = false;
  2696. instance.g_IsEnableCompositePrice = $("#" + instance.g_VisibleContainerId).find('#chk_CompositePrice').is(':checked');
  2697. }
  2698. instance.clearItemSearch();
  2699. instance.refreshAllItems(FromWidget, "PriceTypeClickEvents");
  2700. });
  2701. $("#" + instance.g_VisibleContainerId).find('#chk_CompositePrice').click(function () {
  2702. if ($("#" + instance.g_VisibleContainerId).find('#chk_CompositePrice').is(':checked')) {
  2703. if (instance.g_IsEnablePiecePrice) {
  2704. instance.g_IsEnableCompositePrice = false;
  2705. instance.g_IsEnableCompositePiecePrice = true;
  2706. instance.g_IsEnablePiecePrice = false;
  2707. }
  2708. else {
  2709. instance.g_IsEnableCompositePrice = true;
  2710. instance.g_IsEnableCompositePiecePrice = false;
  2711. instance.g_IsEnablePiecePrice = false;
  2712. }
  2713. }
  2714. else {
  2715. instance.g_IsEnableCompositePrice = false;
  2716. instance.g_IsEnableCompositePiecePrice = false;
  2717. instance.g_IsEnablePiecePrice = $("#" + instance.g_VisibleContainerId).find('#chk_PiecePrice').is(':checked');
  2718. }
  2719. instance.setPriceType();
  2720. if (instance._order.g_IsPurchasePlanning)
  2721. instance.loadPurchasePlanItems($("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val());
  2722. else {
  2723. instance.clearItemSearch();
  2724. instance.refreshAllItems(FromWidget, "PriceTypeClickEvents");
  2725. }
  2726. });
  2727. }
  2728. continueShopping() {
  2729. let instance = this;
  2730. instance.g_FromContinueShopping = true;
  2731. $("#" + instance.g_VisibleContainerId).find(".modal-body").scrollTop(0);
  2732. $("#" + instance.g_VisibleContainerId).find(".tax-error").text("");
  2733. let SearchItem = $("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val();
  2734. if (SearchItem != "" || instance.g_PageIndex != 0) {
  2735. instance.g_PageIndex = 0;
  2736. $("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val("");
  2737. instance.loadItems($("#" + instance.g_VisibleContainerId).find("#txt_SearchItem").val());
  2738. }
  2739. $("#" + instance.g_VisibleContainerId).find(".div_SearchItem").removeClass('floating-label-form-group-with-value');
  2740. $("#" + instance.g_VisibleContainerId).find(".section_CartDetails").addClass('hidden');
  2741. $("#" + instance.g_VisibleContainerId).find(".section_Summary").addClass('hidden');
  2742. $("#" + instance.g_VisibleContainerId).find("#dropup_save").addClass("hidden");
  2743. $("#" + instance.g_VisibleContainerId).find("#btn_Save_New").addClass("hidden");
  2744. $("#" + instance.g_VisibleContainerId).find(".btn_Save_Form").addClass("hidden");
  2745. $("#" + instance.g_VisibleContainerId).find(".section_PriceDetails").addClass('hidden');
  2746. $("#" + instance.g_VisibleContainerId).find(".OrgContactNameLink").removeClass('hidden');
  2747. $("#" + instance.g_VisibleContainerId).find(".section_OrderDetails").addClass("hidden");
  2748. $("#" + instance.g_VisibleContainerId).find(".section_Items").removeClass('hidden');
  2749. if ($("#" + instance.g_VisibleContainerId).find(".section_CartDetails").hasClass('hidden')) {
  2750. $("#" + instance.g_VisibleContainerId).find("#btn_CloseForm_" + $("#" + instance.g_VisibleContainerId).find("#hf_FormId").val()).removeClass('hidden');
  2751. }
  2752. if (!$("#" + instance.g_VisibleContainerId).find(".section_Items").hasClass('hidden')) {
  2753. $("#" + instance.g_VisibleContainerId).find("#btn_Save").addClass('hidden');
  2754. instance._order.showOrHideSaveAsDraft();
  2755. $("#" + instance.g_VisibleContainerId).find(".CheckOutButton").removeClass('hidden');
  2756. }
  2757. if (instance._order.g_IsPurchasePlanning) {
  2758. $("#" + instance.g_VisibleContainerId).find(".section_PurchasePlanSummary").removeClass('hidden');
  2759. $("#" + instance.g_VisibleContainerId).find(".section_PurchasePlan").removeClass('hidden');
  2760. $("#" + instance.g_VisibleContainerId).find(".section_PriceDetails").find(".card-header").text('Description');
  2761. }
  2762. $("#" + instance.g_VisibleContainerId).find(".btn_OrderSaveAsDraft").addClass('hidden');
  2763. $("#" + instance.g_VisibleContainerId).find("#btn_CloseForm_" + $("#" + instance.g_VisibleContainerId).find("#hf_FormId").val()).addClass("mr-auto");
  2764. $("#" + instance.g_VisibleContainerId).find('#ulOrder_Cart .cart-item-chk').addClass('d-none');
  2765. }
  2766. showOfferItems(OrganizationId, ItemId, ItemName, OrderType, element) {
  2767. let instance = this;
  2768. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFiles(["apps/transact/components/invoices/itemofferselection.js", "apps/transact/controls/invoices/invoiceitem.component.js"], function () {
  2769. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(0, "", Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance(), function () {
  2770. Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance().LoadOfferItems(OrganizationId, ItemId, ItemName, OrderType, $("#" + instance.g_VisibleContainerId).find(element), "Order");
  2771. }, Unibase.Platform.Helpers.Size.Large);
  2772. });
  2773. }
  2774. applyOffer(Item) {
  2775. let instance = this;
  2776. let ItemId = Item[0].ItemId;
  2777. let Qty = Item[0].Volume;
  2778. let LoadedItem = instance.g_LoadedItems.find(x => x.ItemId == ItemId);
  2779. let Cartons = Math.ceil(Qty / (LoadedItem.PackCount * LoadedItem.PackSize));
  2780. Qty = ((LoadedItem.PackCount * LoadedItem.PackSize) * Cartons);
  2781. Qty = instance.roundOff(Qty);
  2782. if (instance._order.g_InventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Packs) {
  2783. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find('#txt_Cartons').val(Cartons);
  2784. $("#" + instance.g_VisibleContainerId).find('.cartitem-' + ItemId).find('#txt_Cartons').val(Cartons);
  2785. }
  2786. else if (instance._order.g_InventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.Pieces) {
  2787. let Pieces = Math.ceil((Qty) / LoadedItem.PackSize);
  2788. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find('#txt_Pieces').val(Pieces);
  2789. $("#" + instance.g_VisibleContainerId).find('.cartitem-' + ItemId).find('#txt_Pieces').val(Pieces);
  2790. }
  2791. else if (instance._order.g_InventoryApplyType == Bizgaze.Apps.Transact.Enums.InventoryApplyType.PacksAndPieces) {
  2792. if (Cartons > 0) {
  2793. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find('#txt_Cartons').val(Cartons);
  2794. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find('#txt_Pieces').val("");
  2795. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find('.defaultSelectedPieces').removeClass("floating-label-form-group-with-value");
  2796. $("#" + instance.g_VisibleContainerId).find('.cartitem-' + ItemId).find('#txt_Cartons').val(Cartons);
  2797. $("#" + instance.g_VisibleContainerId).find('.cartitem-' + ItemId).find('#txt_Pieces').val("");
  2798. $("#" + instance.g_VisibleContainerId).find('.cartitem-' + ItemId).find('.defaultSelectedPieces').removeClass("floating-label-form-group-with-value");
  2799. instance.g_PacksFocus = true;
  2800. instance.g_PiecesFocus = false;
  2801. }
  2802. else {
  2803. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find('#txt_Cartons').val("");
  2804. $("#" + instance.g_VisibleContainerId).find('.cartitem-' + ItemId).find('#txt_Cartons').val("");
  2805. }
  2806. }
  2807. else {
  2808. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find('#txt_Cartons').val(Qty);
  2809. $("#" + instance.g_VisibleContainerId).find('.cartitem-' + ItemId).find('#txt_Cartons').val(Qty);
  2810. }
  2811. let element = $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId);
  2812. instance.updateItemsArray(element, "ApplyOffer", false, Qty);
  2813. }
  2814. checkOffers(FromWidget, evnt) {
  2815. return __awaiter(this, void 0, void 0, function* () {
  2816. let instance = this;
  2817. if (instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim && instance._order.g_OrderTypeId != Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim) {
  2818. let ordItems = new Array();
  2819. let applyType = '';
  2820. if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.SalesClaim) {
  2821. applyType = 'Sales';
  2822. }
  2823. else if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Purchase || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim)
  2824. applyType = 'Purchases';
  2825. instance.g_CartItems_New.filter(x => x.IsFocItem == false).forEach(function (c) {
  2826. c.IsFocAdded = false;
  2827. c.FocItemIds = '';
  2828. c.IsOfferDiscountApplied = false;
  2829. c.AppliedOfferVolume = 0;
  2830. let ItemId = c.ItemId;
  2831. let baseqty = Number(c.BaseQty);
  2832. if ((c.IsManualUOM && instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales) || c.IsMultipleUOMs) {
  2833. baseqty = c.Quantity;
  2834. }
  2835. let unitPrice = Number(c.UnitPrice);
  2836. let rowTotal = instance.roundOff(baseqty * unitPrice);
  2837. ordItems.push({
  2838. ItemId: Number(ItemId),
  2839. Quantity: Number(instance.roundOff(baseqty)),
  2840. RowTotal: Number(rowTotal),
  2841. });
  2842. });
  2843. if (FromWidget) {
  2844. let OrderId = Bizgaze.Apps.Transact.Controls.Order.Instance().g_OrderId;
  2845. let OrderItemId = Bizgaze.Apps.Transact.Controls.AddOrderItems.Instance().g_Edit_OrderItemId;
  2846. instance.fileCacheHelper.loadJsFile("apps/transact/managers/orders/ordermanager.js", function () {
  2847. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getOrderItems(OrderId, 0).then(function (response) {
  2848. let data = response.result;
  2849. data = data.filter(x => x.OrderItemId != OrderItemId && x.IsFoc == false);
  2850. for (let d = 0; d < data.length; d++) {
  2851. let ItemId = data[d].ItemId;
  2852. let baseqty = Number(data[d].Quantity);
  2853. let unitPrice = Number(data[d].UnitPrice);
  2854. let rowTotal = instance.roundOff(baseqty * unitPrice);
  2855. ordItems.push({
  2856. ItemId: Number(ItemId),
  2857. Quantity: Number(instance.roundOff(baseqty)),
  2858. RowTotal: Number(rowTotal),
  2859. });
  2860. }
  2861. instance.bindOfferItems(FromWidget, ordItems);
  2862. });
  2863. });
  2864. }
  2865. else {
  2866. instance.bindOfferItems(FromWidget, ordItems);
  2867. }
  2868. }
  2869. else {
  2870. instance.getTotals();
  2871. }
  2872. });
  2873. }
  2874. bindOfferItems(FromWidget, ordItems) {
  2875. var instance = this;
  2876. let IsCart = false;
  2877. if ($("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").is(":visible")) {
  2878. IsCart = true;
  2879. }
  2880. let ApplyDate1 = moment(instance.g_OfferApplyDate, "DD/MM/YYYY").add(1, 'days').format("YYYY/MM/DD");
  2881. let ApplyDate = new Date(ApplyDate1);
  2882. let postData = {
  2883. OrderItems: ordItems,
  2884. ContactId: instance._order.g_OrganizationId,
  2885. ApplyType: instance._order.g_OrderTypeId,
  2886. ApplyDate: ApplyDate
  2887. };
  2888. Bizgaze.Apps.Transact.Managers.OfferManager.Instance().getRelatedOffersByItem(postData).then(function (response) {
  2889. return __awaiter(this, void 0, void 0, function* () {
  2890. instance.g_AppliedOffers = [];
  2891. if (response != null && response.Result.length != 0) {
  2892. let AllFocItems = [];
  2893. for (let i = 0; i < response.Result.length; i++) {
  2894. let data = response.Result[i];
  2895. let appliedItems = data.applyIds.replace(/,\s*$/, "").split(',');
  2896. let discValue = 0;
  2897. let discPercent = 0;
  2898. if (data.PayoutValue > 0)
  2899. discValue = data.PayoutValue;
  2900. else if (data.OPayoutValue > 0)
  2901. discValue = data.OPayoutValue;
  2902. else if (data.PayoutPercent > 0)
  2903. discPercent = data.PayoutPercent;
  2904. let volume = data.Volume;
  2905. let focItems = data.ItemVolumePayouts;
  2906. for (let f = 0; f < focItems.length; f++) {
  2907. if (focItems[f].Quantity != 0) {
  2908. AllFocItems.push(focItems[f]);
  2909. }
  2910. }
  2911. let contactId = instance._order.g_OrganizationId;
  2912. for (let j = 0; j < focItems.length; j++) {
  2913. let focItem_RefItemIds = focItems[j].RefItemIds;
  2914. let focItem_RefItemSKUs = focItems[j].RefItemSKUs;
  2915. let ValidFocIndex = instance.g_ValidFocItems.findIndex(x => x.ItemId == focItems[j].ItemId && focItem_RefItemIds.indexOf(x.RefItemIds) != -1);
  2916. let CartItemIndex = instance.g_CartItems_New.findIndex(x => x.ItemId == focItems[j].ItemId && x.RefItemIds == focItem_RefItemIds);
  2917. if (focItems[j].Quantity > 0 && ((ValidFocIndex != -1 && focItems[j].IsFoC) || (!focItems[j].IsFoC))) {
  2918. let FocItem_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == focItems[j].ItemId && x.RefItemIds == focItem_RefItemIds);
  2919. if (FocItem_Index == -1) {
  2920. instance.addFocItemToCart(contactId, focItems[j].ItemId, focItems[j].Quantity, focItems[j].Discount, focItem_RefItemIds, FromWidget, focItem_RefItemSKUs);
  2921. }
  2922. else {
  2923. instance.editFocCartItem(focItems[j].ItemId, focItems[j].Quantity, FromWidget);
  2924. }
  2925. }
  2926. else if (CartItemIndex != -1) {
  2927. instance.deleteCartItems(focItems[j].ItemId, FromWidget, focItem_RefItemIds);
  2928. }
  2929. }
  2930. for (let m = 0; m < appliedItems.length; m++) {
  2931. let IsSelected = false;
  2932. var sp_ItemIndex = Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance().g_Selected_Plan.findIndex(x => x.PlanVolumeId == data.PlanVolumeId && x.ItemId == Number(appliedItems[m]));
  2933. if (sp_ItemIndex != -1) {
  2934. IsSelected = true;
  2935. }
  2936. instance.g_AppliedOffers.push({
  2937. ItemId: Number(appliedItems[m]),
  2938. OfferId: data.OfferId,
  2939. PlanId: data.PlanId,
  2940. PlanVolumeId: data.PlanVolumeId,
  2941. IsSelected: IsSelected
  2942. });
  2943. let n = instance.g_CartItems_New.findIndex(x => x.ItemId == appliedItems[m] && x.RefItemIds == "");
  2944. if (n != -1) {
  2945. if (!instance._order.g_IsManageOfferDiscount || (instance.g_CartItems_New[n].DiscountValue == 0 && instance.g_CartItems_New[n].DiscountPercent == 0)) {
  2946. if (discValue > 0 || discPercent > 0) {
  2947. instance.g_CartItems_New[n].DiscountValue = discValue;
  2948. instance.g_CartItems_New[n].DiscountPercent = discPercent;
  2949. instance.g_CartItems_New[n].IsFocAdded = true;
  2950. instance.g_CartItems_New[n].IsOfferDiscountApplied = true;
  2951. instance.g_CartItems_New[n].AppliedOfferVolume = volume;
  2952. instance.g_CartItems_New[n].AppliedPlanVolumeId = data.PlanVolumeId;
  2953. instance.g_CartItems_New[n].AppliedOfferId = data.OfferId;
  2954. let Elem = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + instance.g_CartItems_New[n].ItemId);
  2955. let Cart_Elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + instance.g_CartItems_New[n].ItemId);
  2956. let Discount = discValue == 0 ? discPercent : discValue;
  2957. $("#" + instance.g_VisibleContainerId).find(Elem).find("#Ord_txtdiscount").val(Discount);
  2958. $("#" + instance.g_VisibleContainerId).find(Cart_Elem).find("#Ord_txtdiscount").val(Discount);
  2959. let DiscountType = discValue == 0 ? 1 : 2;
  2960. $("#" + instance.g_VisibleContainerId).find(Elem).find(".btnOrder_DiscType").val(DiscountType);
  2961. $("#" + instance.g_VisibleContainerId).find(Cart_Elem).find(".btnOrder_DiscType").val(DiscountType);
  2962. let AssessableAmount = Number(instance.g_CartItems_New[n].Amount);
  2963. let discVal = Number(instance.g_CartItems_New[n].DiscountValue) * Number(instance.g_CartItems_New[n].BaseQty);
  2964. let DiscAmount = Number((instance.g_CartItems_New[n].Amount * discPercent) / 100) + Number(discVal);
  2965. let discAmt = DiscAmount + Number(instance.g_CartItems_New[n].optoutAmount);
  2966. AssessableAmount = Number(AssessableAmount) - Number(discAmt);
  2967. let AmountWithDiscount = Number(instance.g_CartItems_New[n].Amount) - Number(DiscAmount);
  2968. instance.g_CartItems_New[n].DiscountAmount = discAmt;
  2969. instance.g_CartItems_New[n].AmountWithDiscount = AmountWithDiscount;
  2970. instance.g_CartItems_New[n].DiscountType = DiscountType;
  2971. }
  2972. }
  2973. let amount = Number(instance.g_CartItems_New[n].UnitPrice) * Number(instance.g_CartItems_New[n].BaseQty);
  2974. let discAmt = Number(instance.roundOff((amount * discPercent) / 100)) + Number(instance.roundOff(discValue));
  2975. if (discAmt != 0) {
  2976. let assessableAmount = Number(amount) - Number(discAmt);
  2977. }
  2978. else {
  2979. }
  2980. }
  2981. instance.g_CartItems_New.filter(x => x.IsFocItem == false).forEach(function (c) {
  2982. let Elem = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + c.ItemId);
  2983. let Cart_Elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + c.ItemId);
  2984. instance.updateItemsDesign(Elem, "AddFocItem_IsOfferDiscountApplied", IsCart);
  2985. instance.updateItemsDesign(Cart_Elem, "AddFocItem_IsOfferDiscountApplied", IsCart);
  2986. });
  2987. }
  2988. }
  2989. let Ref_Items = instance.g_CartItems_New.filter(x => x.RefItemIds != "");
  2990. for (let r = 0; r < Ref_Items.length; r++) {
  2991. let a = AllFocItems.findIndex(x => x.ItemId == Ref_Items[r].ItemId);
  2992. if (a == -1) {
  2993. instance.deleteCartItems(Ref_Items[r].ItemId, FromWidget, Ref_Items[r].RefItemIds);
  2994. }
  2995. }
  2996. }
  2997. else {
  2998. instance.g_CartItems_New.filter(x => x.IsFocItem == true).forEach(function (c) {
  2999. let Foc_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == c.ItemId && x.RefItemIds != "");
  3000. instance.g_CartItems_New.splice(Foc_Index, 1);
  3001. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + c.ItemId + "-" + c.RefItemIds.replace(/,/g, "-")).remove();
  3002. if (FromWidget) {
  3003. $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + c.ItemId + "-" + c.RefItemIds.replace(/,/g, "-")).remove();
  3004. }
  3005. });
  3006. instance.g_CartItems_New.filter(x => x.IsFocItem == false && x.IsOfferAvailable == true && !instance._order.g_IsManageOfferDiscount).forEach(function (c) {
  3007. if (!FromWidget) {
  3008. let Elem = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + c.ItemId);
  3009. let Cart_Elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + c.ItemId);
  3010. let CartItemIndex = instance.g_CartItems_New.findIndex(x => x.ItemId == c.ItemId);
  3011. if (CartItemIndex != -1) {
  3012. instance.g_CartItems_New[CartItemIndex].DiscountValue = 0;
  3013. instance.g_CartItems_New[CartItemIndex].DiscountPercent = 0;
  3014. instance.g_CartItems_New[CartItemIndex].IsFocAdded = false;
  3015. instance.g_CartItems_New[CartItemIndex].IsOfferDiscountApplied = false;
  3016. instance.g_CartItems_New[CartItemIndex].AppliedOfferVolume = 0;
  3017. instance.g_CartItems_New[CartItemIndex].DiscountAmount = 0;
  3018. instance.g_CartItems_New[CartItemIndex].AmountWithDiscount = instance.g_CartItems_New[CartItemIndex].Amount;
  3019. instance.g_CartItems_New[CartItemIndex].DiscountType = 2;
  3020. }
  3021. instance.updateItemsDesign(Elem, "AddFocItem_IsOfferDiscountApplied", IsCart);
  3022. instance.updateItemsDesign(Cart_Elem, "AddFocItem_IsOfferDiscountApplied", IsCart);
  3023. }
  3024. });
  3025. }
  3026. instance.getTotals();
  3027. if (instance.g_CartItems_New.length == 0) {
  3028. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").html('<li id="0" class="cartitem list-group-item col-xs-12 hidden clear no-border"></li> <li class="list-group-item col-xs-12 no-border EmptyCartLi"><strong>Your Shopping Cart is empty.</strong></li>');
  3029. }
  3030. else {
  3031. $("#" + instance.g_VisibleContainerId).find(".EmptyCartLi").remove();
  3032. }
  3033. });
  3034. });
  3035. }
  3036. addFocItemToCart(ContactId, ItemId, Quantity, Discount, RefItemIds, FromWidget, RefItemSKUs = "") {
  3037. let instance = this;
  3038. let ShippingAddressId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_shippingaddressid").val();
  3039. let BranchId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billfromaddressid").val();
  3040. let LobId = $("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_lobid").val();
  3041. let OrderItemId = 0;
  3042. if (FromWidget) {
  3043. ShippingAddressId = Bizgaze.Apps.Transact.Controls.AddOrderItems.Instance().g_ShippingAddressId;
  3044. BranchId = Bizgaze.Apps.Transact.Controls.AddOrderItems.Instance().g_BranchId;
  3045. LobId = Bizgaze.Apps.Transact.Controls.AddOrderItems.Instance().g_LobId;
  3046. let FocItem = Bizgaze.Apps.Transact.Controls.AddOrderItems.Instance().g_FocItems.find(x => x.ItemId == ItemId);
  3047. if (FocItem != undefined) {
  3048. OrderItemId = FocItem.OrderItemId;
  3049. }
  3050. }
  3051. let ApplyDate1 = moment(instance.g_OfferApplyDate, "DD/MM/YYYY").add(1, 'days').format("YYYY/MM/DD");
  3052. let ApplyDate = new Date(ApplyDate1);
  3053. let postdata = {
  3054. PriceCodeId: Number(instance._order.g_PriceCodeId),
  3055. ContactId: ContactId,
  3056. ShippingAddressId: Number(ShippingAddressId),
  3057. BranchId: Number(BranchId),
  3058. WareHouseId: Number(instance.g_WarehouseId),
  3059. LobId: Number(LobId),
  3060. OrderType: instance._order.g_OrderTypeId,
  3061. OfferOnly: false,
  3062. IsExcise: instance.g_IsExcise,
  3063. SearchTerm: "",
  3064. Page: 0,
  3065. IsCompositePrice: instance.g_IsEnableCompositePrice,
  3066. IsPiecePrice: instance.g_IsEnablePiecePrice,
  3067. IsCompositePiecePrice: instance.g_IsEnableCompositePiecePrice,
  3068. Rows: 10,
  3069. ItemId: ItemId.toString(),
  3070. CountryId: instance._order.g_CountryId,
  3071. ItemGroupId: 0,
  3072. Tags: "",
  3073. IsPoints: instance._order.g_IsPointsOrder,
  3074. Points: instance._order.g_LoyaltyPoints,
  3075. IsEligibleItemsOnly: instance._order.g_LoadEligibleItemsOnly,
  3076. ApplyDate: ApplyDate
  3077. };
  3078. Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItemsForOrder(postdata).then(function (response) {
  3079. let data = response.result[0];
  3080. let LoadedItem_Index = instance.g_LoadedItems.findIndex(z => z.ItemId == data.ItemId);
  3081. if (LoadedItem_Index == -1) {
  3082. instance.g_LoadedItems.push(data);
  3083. }
  3084. else {
  3085. instance.g_LoadedItems[LoadedItem_Index].TaxPercentList = data.TaxPercentList;
  3086. }
  3087. let ItemName = data.ItemName;
  3088. let ItemId = Number(data.ItemId);
  3089. let Packs = 0;
  3090. let PackCount = data.PackCount;
  3091. let PackSize = data.PackSize;
  3092. let UnitPrice = data.UnitPrice;
  3093. let UnitName = data.UnitName;
  3094. let ExpectedPrice = data.UnitPrice;
  3095. let discType = 1;
  3096. let DiscPercent = 0;
  3097. let DiscVal = 0;
  3098. let PriceListId = 0;
  3099. let AvailablePacks = data.AvailablePacks;
  3100. let AvailablePieces = data.AvailablePieces;
  3101. let AvailableQuantity = data.AvailableQuantity;
  3102. let TotalAvailablePieces = data.TotalAvailablePieces;
  3103. let SKU = data.SKU;
  3104. if (Number(PackCount) == 0)
  3105. PackCount = 1;
  3106. if (Number(PackSize) == 0)
  3107. PackSize = 1;
  3108. Quantity = instance.roundOffIgnoreZerosAfterDecimal(Quantity);
  3109. Packs = Number(Quantity) / (PackCount * PackSize);
  3110. let amount = Number(Quantity) * UnitPrice;
  3111. let assessableAmount = Number(amount);
  3112. let discAmt = 0;
  3113. if (discType == 2) {
  3114. DiscVal = Discount;
  3115. discAmt = Number(DiscVal) * Number(Quantity);
  3116. assessableAmount = instance.roundOff(amount - discAmt);
  3117. }
  3118. else if (discType == 1) {
  3119. DiscPercent = Discount;
  3120. discAmt = Number((amount * DiscPercent) / 100);
  3121. assessableAmount = instance.roundOff(Number(assessableAmount) - Number(discAmt));
  3122. if (amount == 0)
  3123. assessableAmount = 0;
  3124. }
  3125. let BaseQty = Number(PackCount) * Number(PackSize) * Number(Packs);
  3126. let IsCalculateTax = instance._order.g_IsCalculateTax;
  3127. let TaxGroupId = 0;
  3128. let TaxAmount = 0;
  3129. let StrTaxPercents = "";
  3130. let TaxGroupName = "";
  3131. let IsTaxError = false;
  3132. if (IsCalculateTax) {
  3133. if (data.TaxGroupId == 0) {
  3134. IsTaxError = true;
  3135. }
  3136. else {
  3137. TaxGroupId = data.TaxGroupId;
  3138. TaxGroupName = data.TaxGroupName;
  3139. for (let p = 0; p < data.TaxPercentList.length; p++) {
  3140. let percen = data.TaxPercentList[p];
  3141. let tax = assessableAmount * percen.Percentage / 100;
  3142. TaxAmount += tax;
  3143. }
  3144. StrTaxPercents = data.strTaxPercents;
  3145. instance.getPriceTypeValues(ItemId);
  3146. if (instance.g_IsEnablePiecePrice) {
  3147. UnitPrice = data.PiecePrice;
  3148. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.PiecePrice;
  3149. }
  3150. else if (instance.g_IsEnableCompositePrice) {
  3151. UnitPrice = data.CompositePrice;
  3152. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.CompositePrice;
  3153. }
  3154. else if (instance.g_IsEnableCompositePiecePrice) {
  3155. UnitPrice = data.CompositePiecePrice;
  3156. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.Both;
  3157. }
  3158. else {
  3159. instance.g_PriceTypeId = Bizgaze.Apps.Transact.Enums.PriceType.None;
  3160. }
  3161. }
  3162. }
  3163. let CItemIndex = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds != "");
  3164. if (CItemIndex != -1) {
  3165. instance.g_CartItems_New.splice(CItemIndex, 1);
  3166. }
  3167. let ItemIndex = instance.g_CartItems_New.length + 1;
  3168. instance.g_CartItems_New.push({
  3169. OrderItemId: OrderItemId,
  3170. ItemIndex: ItemIndex,
  3171. ItemId: ItemId,
  3172. ItemName: ItemName,
  3173. Packs: Quantity,
  3174. Pieces: 0,
  3175. PriceListId: 0,
  3176. UnitPrice: UnitPrice,
  3177. UnitPriceWithOutTax: UnitPrice,
  3178. ExpectedPrice: ExpectedPrice,
  3179. ActualPrice: UnitPrice,
  3180. PackCount: PackCount,
  3181. PackSize: PackSize,
  3182. UnitName: UnitName,
  3183. Quantity: Quantity,
  3184. SKU: SKU,
  3185. PartNo: "",
  3186. Amount: amount,
  3187. AmountWithDiscount: assessableAmount,
  3188. DiscountPercent: DiscPercent,
  3189. DiscountValue: DiscVal,
  3190. DiscountType: discType,
  3191. DiscountAmount: discAmt,
  3192. ItemValueAfterDiscount: assessableAmount,
  3193. StrTaxPercents: StrTaxPercents,
  3194. AvailableQuantity: AvailableQuantity,
  3195. AvailablePacks: AvailablePacks,
  3196. AvailablePieces: AvailablePieces,
  3197. TotalAvailablePieces: TotalAvailablePieces,
  3198. ExchangeDC: false,
  3199. IsAfterTax: false,
  3200. BaseQty: BaseQty,
  3201. IsFocItem: true,
  3202. optoutAmount: 0,
  3203. TaxGroupId: TaxGroupId,
  3204. TaxGroupName: TaxGroupName,
  3205. TaxAmount: TaxAmount,
  3206. TaxRateAmount: 0,
  3207. TaxRate: data.TaxRate,
  3208. TaxPercentage: data.TaxPercentage,
  3209. IsOfferAvailable: false,
  3210. Description: "",
  3211. Discountable: false,
  3212. PiecePrice: 0,
  3213. CompositePrice: 0,
  3214. CompositePiecePrice: 0,
  3215. IsCheckPendingItems: false,
  3216. IsError: false,
  3217. ErrorMsg: "",
  3218. ErrorClass: "text-danger",
  3219. IsTaxError: IsTaxError,
  3220. IsLeverageError: false,
  3221. IsFocAdded: false,
  3222. RefOrderItemId: 0,
  3223. RefItemIds: RefItemIds,
  3224. RefItemSKUs: RefItemSKUs,
  3225. FocItemIds: "",
  3226. DiscountGroupId: 0,
  3227. IsOfferDiscountApplied: false,
  3228. AppliedOfferVolume: 0,
  3229. AppliedPlanVolumeId: 0,
  3230. AppliedOfferId: 0,
  3231. optoutOfferGroupId: 0,
  3232. SuggestedPacks: 0,
  3233. MinPacks: 0,
  3234. AvgPacks: 0,
  3235. InwardOrderPacks: 0,
  3236. OutwardOrderPacks: 0,
  3237. IsManualUOM: data.IsManualUOM,
  3238. UOMs: data.UOMs,
  3239. IsMultipleUOMs: data.IsMultipleUOMs,
  3240. UOMSchemaId: data.UOMSchemaId,
  3241. MultipleUOMs: data.MultipleUOMs,
  3242. SelectedUnitId: 1,
  3243. SelectedUnitName: UnitName,
  3244. DefaultSize: data.DefaultSize,
  3245. IsBoMAvailable: data.IsBoMAvailable,
  3246. IsSpecialPrice: data.IsSpecialPrice,
  3247. ConversionQuantity: 0,
  3248. HSNId: data.HSNId,
  3249. RowTotal: 0,
  3250. RowDiscount: 0,
  3251. TaxTotal: 0
  3252. });
  3253. if (FromWidget) {
  3254. if (RefItemIds == undefined) {
  3255. RefItemIds = "";
  3256. }
  3257. data.RefItemIds = RefItemIds;
  3258. if (RefItemIds != "") {
  3259. $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId + "-" + RefItemIds.replace(/,/g, "-")).remove();
  3260. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId + "-" + RefItemIds.replace(/,/g, "-")).remove();
  3261. }
  3262. let html = instance.getItemDesign(data, FromWidget);
  3263. $("#" + instance.g_VisibleContainerId).find(".variant-item:last").after(html);
  3264. let elem = $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId + "-" + RefItemIds.replace(/,/g, "-"));
  3265. if (elem != undefined && elem.length > 0) {
  3266. instance.updateItemsDesign(elem, "FromWidget_FocItem", false, true);
  3267. }
  3268. $("#" + instance.g_VisibleContainerId).find(".defaultSelectedCartons").addClass("floating-label-form-group-with-value");
  3269. }
  3270. else {
  3271. instance.addCartItem(ItemId, true);
  3272. }
  3273. instance.getTotals();
  3274. });
  3275. }
  3276. editFocCartItem(ItemId, Quantity, FromWidget) {
  3277. let instance = this;
  3278. let CartItem = instance.g_CartItems_New.find(x => x.ItemId == ItemId && x.RefItemIds != "");
  3279. let PackCount = CartItem.PackCount;
  3280. let PackSize = CartItem.PackSize;
  3281. let UnitPrice = CartItem.UnitPrice;
  3282. let discType = CartItem.DiscountType;
  3283. let DiscVal = CartItem.DiscountValue;
  3284. let DiscPercent = CartItem.DiscountPercent;
  3285. let discAmt = CartItem.DiscountAmount;
  3286. Quantity = instance.roundOffIgnoreZerosAfterDecimal(Quantity);
  3287. let Packs = Number(Quantity) / (PackCount * PackSize);
  3288. let amount = Number(Quantity) * UnitPrice;
  3289. let assessableAmount = Number(amount);
  3290. let DiscAmount = Number((amount * DiscPercent) / 100) + Number(DiscVal);
  3291. assessableAmount = instance.roundOff(amount - DiscAmount);
  3292. if (amount == 0)
  3293. assessableAmount = 0;
  3294. let BaseQty = Number(PackCount) * Number(PackSize) * Number(Packs);
  3295. let IsCalculateTax = instance._order.g_IsCalculateTax;
  3296. let AmountWithDiscount = Number(amount) - Number(DiscAmount);
  3297. let TaxAmount = 0;
  3298. let LoadedItem = instance.g_LoadedItems.find(x => x.ItemId == ItemId);
  3299. if (IsCalculateTax) {
  3300. if (LoadedItem.TaxGroupId != 0) {
  3301. for (let p = 0; p < LoadedItem.TaxPercentList.length; p++) {
  3302. let percen = LoadedItem.TaxPercentList[p];
  3303. let tax = assessableAmount * percen.Percentage / 100;
  3304. TaxAmount += tax;
  3305. }
  3306. }
  3307. }
  3308. CartItem.BaseQty = BaseQty;
  3309. CartItem.TaxAmount = TaxAmount;
  3310. CartItem.Packs = Quantity;
  3311. CartItem.Amount = amount;
  3312. CartItem.Quantity = Quantity;
  3313. CartItem.AmountWithDiscount = AmountWithDiscount;
  3314. let Foc_elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId + "-" + CartItem.RefItemIds.replace(/,/g, "-"));
  3315. if (FromWidget) {
  3316. Foc_elem = $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId + "-" + CartItem.RefItemIds.replace(/,/g, "-"));
  3317. }
  3318. instance.updateItemsDesign(Foc_elem, "EditFocItem_IsOfferDiscountApplied", true, true);
  3319. }
  3320. getSelectionStart(o) {
  3321. }
  3322. isNumberKey(evt) {
  3323. let instance = this;
  3324. if (evt.type == "paste") {
  3325. let pastedData = evt.clipboardData.getData('text');
  3326. let regExp = /[a-zA-Z]/g;
  3327. if (regExp.test(pastedData)) {
  3328. evt.preventDefault();
  3329. return false;
  3330. }
  3331. }
  3332. else if (evt.type == "input") {
  3333. const inputVal = $("#" + instance.g_VisibleContainerId).find(evt.currentTarget).val();
  3334. $("#" + instance.g_VisibleContainerId).find(evt.currentTarget).val(inputVal.replace(/\D/g, ''));
  3335. }
  3336. else {
  3337. if (evt.which != 8 && evt.which != 0 && (evt.which < 48 || evt.which > 57)) {
  3338. return false;
  3339. }
  3340. }
  3341. return true;
  3342. }
  3343. validateFloatKeyPress(el, evt) {
  3344. var instance = this;
  3345. if (evt.type == "input") {
  3346. const inputVal = $("#" + instance.g_VisibleContainerId).find(el).val();
  3347. $("#" + instance.g_VisibleContainerId).find(el).val(inputVal.replace(/[^\d.]|\.(?=.*\.)/g, ''));
  3348. return;
  3349. }
  3350. if (evt.type == "paste") {
  3351. let pastedData = evt.clipboardData.getData('text');
  3352. let regExp = /[^\d.]|\.(?=.*\.)/g;
  3353. if (regExp.test(pastedData)) {
  3354. evt.preventDefault();
  3355. return false;
  3356. }
  3357. return;
  3358. }
  3359. let charCode = (evt.which) ? evt.which : evt.keyCode;
  3360. let number = el.value.split('.');
  3361. if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
  3362. return false;
  3363. }
  3364. if (number.length > 1 && charCode == 46) {
  3365. return false;
  3366. }
  3367. let caratPos = instance.getSelectionStart(el);
  3368. let dotPos = el.value.indexOf(".");
  3369. if (caratPos > dotPos && dotPos > -1 && (number[1].length > 1)) {
  3370. return false;
  3371. }
  3372. return true;
  3373. }
  3374. countDecimals(n) {
  3375. let decimalcount = 0;
  3376. let decimal = n.toString().split(".");
  3377. if (decimal.length == 1) {
  3378. decimalcount = 0;
  3379. }
  3380. else {
  3381. decimalcount = decimal[1].length;
  3382. }
  3383. return decimalcount;
  3384. }
  3385. getIncrementValue(n) {
  3386. let instance = this;
  3387. let incVal = 1;
  3388. let decimalCount = instance.countDecimals(n);
  3389. if (decimalCount == 0) {
  3390. incVal = 1;
  3391. }
  3392. else {
  3393. let dv = "0.";
  3394. for (let i = 0; i < decimalCount - 1; i++) {
  3395. dv += "0";
  3396. }
  3397. dv += "1";
  3398. incVal = Number(dv);
  3399. }
  3400. return incVal;
  3401. }
  3402. checkValidations(ItemId, IsCart) {
  3403. let instance = this;
  3404. let errormessage = "";
  3405. if (ItemId != 0) {
  3406. let element;
  3407. let Item;
  3408. if (IsCart) {
  3409. let CartItem_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds == "");
  3410. Item = instance.g_CartItems_New[CartItem_Index];
  3411. element = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId);
  3412. }
  3413. else {
  3414. let SelectedItem_Index = instance.g_SelectedItems.findIndex(x => x.ItemId == ItemId && x.RefItemIds == "");
  3415. Item = instance.g_SelectedItems[SelectedItem_Index];
  3416. element = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId);
  3417. }
  3418. if (Item != undefined) {
  3419. element.find(".tax-error").text("");
  3420. Item.IsError = false;
  3421. let price = Item.UnitPrice;
  3422. let actualprice = Item.ActualPrice;
  3423. if (price == 0) {
  3424. Item.ErrorMsg += "\n Unit price is zero";
  3425. element.find(".tax-error").text("Unit price is zero").removeClass("text-danger").addClass("text-warning");
  3426. }
  3427. if (price < actualprice && instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales) {
  3428. Item.IsError = true;
  3429. element.find(".tax-error").text("Unit price must be greater than " + actualprice + "").addClass("text-danger").removeClass("text-warning");
  3430. Item.ErrorMsg += "\n Unit price must greater than " + actualprice + "";
  3431. }
  3432. if (!instance._order.g_IsAdmin) {
  3433. if (((Item.DiscountPercent > instance._order.g_LeveragePercent) || (((Item.DiscountValue / Item.UnitPrice) * 100) > instance._order.g_LeveragePercent)) && instance._order.g_IsLeverageApplied == true) {
  3434. Item.IsLeverageError = true;
  3435. $("#" + instance.g_VisibleContainerId).find(element).find("#LeverageErrorTxt").removeClass("hidden");
  3436. $("#" + instance.g_VisibleContainerId).find('.empLeverage').text(instance._order.g_LeveragePercent.toString());
  3437. if ($("#" + instance.g_VisibleContainerId).find('.leverage-Warning').hasClass('hidden'))
  3438. $("#" + instance.g_VisibleContainerId).find('.leverage-Warning').removeClass('hidden');
  3439. }
  3440. else {
  3441. Item.IsLeverageError = false;
  3442. $("#" + instance.g_VisibleContainerId).find(element).find("#LeverageErrorTxt").addClass("hidden");
  3443. if (!$("#" + instance.g_VisibleContainerId).find('.leverage-Warning').hasClass('hidden'))
  3444. $("#" + instance.g_VisibleContainerId).find('.leverage-Warning').addClass('hidden');
  3445. }
  3446. }
  3447. else {
  3448. Item.IsLeverageError = false;
  3449. }
  3450. if (Item.HSNId == 0 && !instance._order.g_IsPointsOrder) {
  3451. Item.IsError = true;
  3452. Item.ErrorMsg = "HSN not assigned";
  3453. element.find(".tax-error").text("HSN not assigned").addClass("text-danger").removeClass("text-warning");
  3454. }
  3455. if (Item.IsTaxError && Item.BaseQty != 0 && !instance._order.g_IsPurchasePlanning && IsCart) {
  3456. Item.IsError = true;
  3457. Item.ErrorMsg = "Tax not assigned";
  3458. element.find(".tax-error").text("Tax not assigned").addClass("text-danger").removeClass("text-warning");
  3459. }
  3460. if (Item.DiscountPercent > 100) {
  3461. element.find(".tax-error").text("Discount % can't be greater than 100").addClass("text-danger").removeClass("text-warning");
  3462. Item.ErrorMsg += "\n Discount % can't be greater than 100";
  3463. Item.IsError = true;
  3464. }
  3465. if (Item.AmountWithDiscount < 0) {
  3466. element.find(".tax-error").text("Item total can't be less than zero").addClass("text-danger").removeClass("text-warning");
  3467. Item.ErrorMsg += "\n Item total can't be less than zero";
  3468. Item.IsError = true;
  3469. }
  3470. if (instance._order.g_IsSC_to_PC && !instance._order.g_IsFromPurchaseIndent) {
  3471. let g_SC_PC_Index = instance.g_SC_PC_CartItems.findIndex(x => x.ItemId == Item.ItemId);
  3472. let ActualQty = instance.g_SC_PC_CartItems[g_SC_PC_Index].Quantity;
  3473. if (g_SC_PC_Index != -1) {
  3474. if (Item.Quantity > ActualQty) {
  3475. element.find(".tax-error").text("Qty can't be greater than " + ActualQty).addClass("text-danger").removeClass("text-warning");
  3476. Item.ErrorMsg += "\n Qty can't be greater than " + ActualQty;
  3477. Item.IsError = true;
  3478. }
  3479. }
  3480. }
  3481. }
  3482. }
  3483. instance.checkErrors();
  3484. instance.checkEnablePieces();
  3485. instance.checkEnablePacks();
  3486. return errormessage;
  3487. }
  3488. checkErrors() {
  3489. let instance = this;
  3490. let IsCart = false;
  3491. if (!$("#" + instance.g_VisibleContainerId).find("#Items-list").is(":visible")) {
  3492. IsCart = true;
  3493. }
  3494. let Items = [];
  3495. if (IsCart) {
  3496. Items = instance.g_CartItems_New;
  3497. }
  3498. else {
  3499. Items = instance.g_SelectedItems;
  3500. }
  3501. let errors = Items.filter(x => x.IsError == true);
  3502. let leverageErrors = Items.filter(x => x.IsLeverageError == true);
  3503. if (leverageErrors.length == 0) {
  3504. instance._order.g_IsApprovalRequired = false;
  3505. if (!$("#" + instance.g_VisibleContainerId).find('.leverage-Warning').hasClass('hidden'))
  3506. $("#" + instance.g_VisibleContainerId).find('.leverage-Warning').addClass('hidden');
  3507. }
  3508. else {
  3509. instance._order.g_IsApprovalRequired = true;
  3510. $("#" + instance.g_VisibleContainerId).find('.empLeverage').text(instance._order.g_LeveragePercent.toString());
  3511. if ($("#" + instance.g_VisibleContainerId).find('.leverage-Warning').hasClass('hidden'))
  3512. $("#" + instance.g_VisibleContainerId).find('.leverage-Warning').removeClass('hidden');
  3513. }
  3514. if (errors.length == 0) {
  3515. instance.enableSave();
  3516. }
  3517. else {
  3518. instance.disableSave();
  3519. }
  3520. }
  3521. checkEnablePieces() {
  3522. let instance = this;
  3523. let picesfound = instance.g_CartItems_New.filter(x => x.Pieces > 0);
  3524. if (picesfound.length > 0) {
  3525. $("#" + instance.g_VisibleContainerId).find('#chk_Pieces').attr('disabled', "true");
  3526. $("#" + instance.g_VisibleContainerId).find(".divEnablePieces").removeClass("checkbox-primary");
  3527. }
  3528. else {
  3529. $("#" + instance.g_VisibleContainerId).find('#chk_Pieces').removeAttr('disabled');
  3530. $("#" + instance.g_VisibleContainerId).find(".divEnablePieces").addClass("checkbox-primary");
  3531. }
  3532. }
  3533. checkEnablePacks() {
  3534. let instance = this;
  3535. let packsfound = instance.g_CartItems_New.filter(x => x.Packs > 0);
  3536. if (packsfound.length > 0) {
  3537. $("#" + instance.g_VisibleContainerId).find('#chk_Packs').attr('disabled', "true");
  3538. $("#" + instance.g_VisibleContainerId).find(".divEnablePacks").removeClass("checkbox-primary");
  3539. }
  3540. else {
  3541. $("#" + instance.g_VisibleContainerId).find('#chk_Packs').removeAttr('disabled');
  3542. $("#" + instance.g_VisibleContainerId).find(".divEnablePacks").addClass("checkbox-primary");
  3543. }
  3544. }
  3545. checkLoyalityErrors(element) {
  3546. let instance = this;
  3547. if (instance._order.g_IsPointsOrder) {
  3548. let TotalQty = 0;
  3549. let TotalCartQty = 0;
  3550. let GrossAmount = 0;
  3551. let ItemId = Number($("#" + instance.g_VisibleContainerId).find(element).find(".hfOrder_ItemId").val());
  3552. let TotalPoints = instance._order.g_LoyaltyPoints;
  3553. instance.g_CartItems_New.forEach(x => TotalQty += x.UnitPrice * x.BaseQty);
  3554. if (instance._order.g_LoyaltyPoints < TotalQty) {
  3555. element.find("#txt_Cartons").val(0);
  3556. instance.updateItemsArray(element, "LoyaltyError", false);
  3557. element.find(".tax-error").text("Redeem Quantity can't be greater than Loyalty Points").removeClass("text-danger").addClass("text-warning");
  3558. instance.deleteCartItems(ItemId);
  3559. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").find(".cartitem-" + ItemId).remove();
  3560. let ItemIndex = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds == "");
  3561. if (ItemIndex != -1) {
  3562. instance.g_CartItems_New.splice(ItemIndex, 1);
  3563. }
  3564. TotalQty = 0;
  3565. instance.g_CartItems_New.forEach(x => TotalQty += x.UnitPrice * x.BaseQty);
  3566. }
  3567. instance.g_CartItems_New.forEach(x => TotalCartQty += x.BaseQty);
  3568. instance.g_CartItems_New.forEach(x => GrossAmount += x.UnitPrice * x.BaseQty);
  3569. $("#" + instance.g_VisibleContainerId).find("#lblSummary_GrossAmount, #lblSummary_AssessableTotal, #lblSummary_NetTotal").text(GrossAmount);
  3570. $("#" + instance.g_VisibleContainerId).find("#lblSummary_TotalDiscount").text("0.00");
  3571. $("#" + instance.g_VisibleContainerId).find("#OverallOrderQuantity").text(TotalCartQty);
  3572. $("#" + instance.g_VisibleContainerId).find("#AvailablePoints").text(TotalPoints - TotalQty);
  3573. $("#" + instance.g_VisibleContainerId).find("#AvailablePoints_header").text(TotalPoints - TotalQty);
  3574. $("#" + instance.g_VisibleContainerId).find("#RedeemPoints").text(TotalQty);
  3575. }
  3576. }
  3577. disableSave() {
  3578. let instance = this;
  3579. $("#" + instance.g_VisibleContainerId).find(".btn_Save_Form").find("button").attr("disabled", "disabled").css("cursor", "not-allowed");
  3580. $("#" + instance.g_VisibleContainerId).find(".btn_OrderSaveAsDraft").attr("disabled", "disabled").css("cursor", "not-allowed");
  3581. return false;
  3582. }
  3583. enableSave() {
  3584. let instance = this;
  3585. $("#" + instance.g_VisibleContainerId).find(".btn_Save_Form").find("button").removeAttr("disabled").css("cursor", "auto");
  3586. $("#" + instance.g_VisibleContainerId).find(".btn_OrderSaveAsDraft").removeAttr("disabled").css("cursor", "auto");
  3587. }
  3588. checkPendingPopup(ItemId, CartItemIndex, FromWidget = false) {
  3589. let instance = this;
  3590. let branchId = instance._order.g_BranchId;
  3591. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getPendingOrderItemsByItemAndCustomer(instance._order.g_OrderTypeId, ItemId, instance._order.g_OrganizationId, 0, 20, branchId, instance._order.g_OrderId).then(function (response) {
  3592. if (response.result.length > 0) {
  3593. let quantity = 0;
  3594. let item = [];
  3595. for (let i = 0; i < response.result.length; i++) {
  3596. item = response.result[i];
  3597. quantity += item.Quantity - item.DeliveredQuantity;
  3598. }
  3599. quantity = instance.roundOff(quantity);
  3600. let msg = item.ItemName + " have " + quantity + " pending quantity..! Are you sure to continue ??";
  3601. bootbox.confirm({
  3602. message: msg,
  3603. closeButton: false,
  3604. buttons: {
  3605. confirm: {
  3606. label: 'Yes',
  3607. className: 'btn-success'
  3608. },
  3609. cancel: {
  3610. label: 'No',
  3611. className: 'btn-danger'
  3612. }
  3613. },
  3614. callback: function (result) {
  3615. debugger;
  3616. let Item = instance.g_SelectedItems.find(x => x.ItemId == ItemId);
  3617. let elem = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId);
  3618. if (result) {
  3619. if (Item != null) {
  3620. Item.IsCheckPendingItems = false;
  3621. }
  3622. if (FromWidget) {
  3623. instance.checkOffers(FromWidget, "CheckPendingPopUp_FromWidget");
  3624. }
  3625. else {
  3626. if (Item == null) {
  3627. instance.addCartItem(ItemId);
  3628. }
  3629. else {
  3630. instance.updateItemsArray(elem, "Plus");
  3631. }
  3632. }
  3633. }
  3634. else {
  3635. $("#" + instance.g_VisibleContainerId).find('#modal_popup_EditLineItem').modal('hide');
  3636. bootbox.hideAll();
  3637. $("#" + instance.g_VisibleContainerId).find(elem).find(".txtOrder_ItemCount").val(0);
  3638. instance.updateItemsArray(elem, "PendingPopCancel");
  3639. if (instance._order.g_IsPurchasePlanning)
  3640. $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId).find(".chk_PurPlanItem").prop("checked", false);
  3641. return false;
  3642. }
  3643. }
  3644. });
  3645. }
  3646. else {
  3647. if (CartItemIndex != -1) {
  3648. let elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId);
  3649. if (FromWidget) {
  3650. elem = $("#" + instance.g_VisibleContainerId).find(".variant-addeditem-" + ItemId);
  3651. }
  3652. instance.updateItemsDesign(elem, "EditCartItem", true);
  3653. }
  3654. else {
  3655. instance.addCartItem(ItemId);
  3656. }
  3657. }
  3658. });
  3659. }
  3660. addCartItem(ItemId, IsFocItem = false) {
  3661. debugger;
  3662. let instance = this;
  3663. let CartItems_Index = -1;
  3664. if (IsFocItem) {
  3665. CartItems_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds != "");
  3666. }
  3667. else {
  3668. CartItems_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds == "");
  3669. }
  3670. let CartItm = instance.g_CartItems_New[CartItems_Index];
  3671. let elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId);
  3672. let RefItemIds = CartItm.RefItemIds;
  3673. if (RefItemIds != "") {
  3674. elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId + "-" + RefItemIds.replace(/,/g, "-"));
  3675. $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId + "-" + RefItemIds.replace(/,/g, "-")).remove();
  3676. }
  3677. let html = instance.getItemDesign(CartItm, false, true);
  3678. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").append(html);
  3679. elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId);
  3680. let evnt = "EditCartItem";
  3681. if (CartItm.IsFocItem) {
  3682. evnt = "EditFocItem";
  3683. }
  3684. if (RefItemIds != "") {
  3685. elem = $("#" + instance.g_VisibleContainerId).find(".cartitem-" + ItemId + "-" + RefItemIds.replace(/,/g, "-"));
  3686. }
  3687. instance.updateItemsDesign(elem, evnt, true, IsFocItem);
  3688. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").find(".chk_PurPlanItem").addClass("hidden");
  3689. instance.allItemEvents(elem);
  3690. }
  3691. deleteCartItems(ItemId, FromWidget = false, RefItemIds = "", event = "") {
  3692. let instance = this;
  3693. let itemelement = $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId);
  3694. let element_name = "cartitem-";
  3695. if (FromWidget) {
  3696. element_name = "variant-addeditem-";
  3697. }
  3698. $("#" + instance.g_VisibleContainerId).find("." + element_name + ItemId).remove();
  3699. let FocItems = instance.g_CartItems_New.filter(x => x.RefItemIds.indexOf(ItemId) != -1);
  3700. for (let f = 0; f < FocItems.length; f++) {
  3701. let Foc_Index = instance.g_CartItems_New.findIndex(x => x.ItemId == FocItems[f].ItemId && x.RefItemIds == FocItems[f].RefItemIds);
  3702. $("#" + instance.g_VisibleContainerId).find("." + element_name + FocItems[f].ItemId + "-" + FocItems[f].RefItemIds.replace(/,/g, "-")).remove();
  3703. instance.g_CartItems_New.splice(Foc_Index, 1);
  3704. }
  3705. let deletecartitemindex = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId && x.RefItemIds == RefItemIds);
  3706. let deleteitemindex = instance.g_SelectedItems.findIndex(x => x.ItemId == ItemId && x.RefItemIds == RefItemIds);
  3707. if (deleteitemindex != -1) {
  3708. instance.g_SelectedItems.splice(deleteitemindex, 1);
  3709. }
  3710. if (deletecartitemindex != -1) {
  3711. if (!instance._order.g_IsPurchasePlanning) {
  3712. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find(".txtOrder_ItemCount,.txtOrder_ItemPieceCount").val("");
  3713. if (event == "") {
  3714. instance.resetItemDetails(ItemId);
  3715. }
  3716. else {
  3717. if (event == "Plus" || event == "Minus" || event == "Packs" || event == "Minus") {
  3718. instance.resetItemDetails(ItemId);
  3719. }
  3720. }
  3721. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find("#DiscountOpenBracket").addClass('hidden');
  3722. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find("#QuantityAndDiscountSpan").text('');
  3723. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find(".defaultSelectedCartons").removeClass('floating-label-form-group-with-value');
  3724. }
  3725. if (deletecartitemindex != -1) {
  3726. instance.g_CartItems_New.splice(deletecartitemindex, 1);
  3727. if (RefItemIds != "") {
  3728. $("#" + instance.g_VisibleContainerId).find("." + element_name + ItemId + "-" + RefItemIds.replace(/,/g, "-")).remove();
  3729. }
  3730. else {
  3731. $("#" + instance.g_VisibleContainerId).find("." + element_name + ItemId).remove();
  3732. }
  3733. }
  3734. $(this).parents(".cartitem").remove();
  3735. if (!instance._order.g_IsPointsOrder && !instance._order.g_IsPurchasePlanning) {
  3736. instance.checkOffers(false, "DeleteCartItem");
  3737. }
  3738. if (instance.g_CartItems_New.length == 0) {
  3739. $("#" + instance.g_VisibleContainerId).find("#ulOrder_Cart").html('<li id="0" class="cartitem list-group-item col-xs-12 hidden clear no-border"></li> <li class="list-group-item col-xs-12 no-border EmptyCartLi"><strong>Your Shopping Cart is empty.</strong></li>');
  3740. }
  3741. instance.getTotals(ItemId);
  3742. instance.checkErrors();
  3743. instance.checkLoyalityErrors(itemelement);
  3744. }
  3745. }
  3746. resetItemDetails(ItemId) {
  3747. let instance = this;
  3748. let LoadedItem_Index = instance.g_LoadedItems.findIndex(x => x.ItemId == ItemId);
  3749. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find("#Ord_txtdiscount, #txt_Description").val("");
  3750. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find(".discountFloatLabels, .descriptionFloatLabels").removeClass('floating-label-form-group-with-value');
  3751. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find(".btnOrder_DiscType").val(2);
  3752. let Items_Price_Index = instance.g_ItemsUnitPrice_New.findIndex(x => x.ItemId == ItemId);
  3753. if (Items_Price_Index != -1) {
  3754. let UnitPrice = instance.g_LoadedItems[LoadedItem_Index].UnitPrice;
  3755. instance.g_ItemsUnitPrice_New[Items_Price_Index].UnitPrice = UnitPrice;
  3756. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find("#txt_editItemPrice").val(UnitPrice);
  3757. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find(".editItemPrice").text(UnitPrice);
  3758. $("#" + instance.g_VisibleContainerId).find('.variant-addeditem-' + ItemId).find("#chkItem_ExchangeDC_" + ItemId).prop("checked", false);
  3759. }
  3760. }
  3761. roundOff(n, decimalValue = 2) {
  3762. return Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(n, decimalValue);
  3763. }
  3764. roundOffIgnoreZerosAfterDecimal(n, decimalValue = 2) {
  3765. n = Number(n);
  3766. return Number(n.toFixed(decimalValue));
  3767. }
  3768. getPriceTypeValues(ItemId, Packs = 0, Pieces = 0) {
  3769. let instance = this;
  3770. let taxpercentage = 0, TaxRate = 0, TaxRateAmount = 0, strTaxPercents = "", CompositePiecePriceTaxRate = 0;
  3771. let LoadedItem = instance.g_LoadedItems.find(x => x.ItemId == ItemId);
  3772. if (LoadedItem != undefined) {
  3773. let taxPercentList = LoadedItem.TaxPercentList;
  3774. let PackSize = LoadedItem.PackSize;
  3775. let ItemUnitPrices = instance.g_ItemsUnitPrice_New.find(x => x.ItemId == ItemId);
  3776. let UnitPrice = 0;
  3777. if (ItemUnitPrices != undefined) {
  3778. UnitPrice = ItemUnitPrices.UnitPrice;
  3779. }
  3780. let CartItemIndex = instance.g_CartItems_New.findIndex(x => x.ItemId == ItemId);
  3781. let PiecePrice = Number(UnitPrice) * Number(PackSize);
  3782. if (taxPercentList != null) {
  3783. for (let i = 0; i < taxPercentList.length; i++) {
  3784. let percen = taxPercentList[i];
  3785. taxpercentage += percen.Percentage;
  3786. TaxRate += UnitPrice * percen.Percentage / 100;
  3787. CompositePiecePriceTaxRate += PiecePrice * percen.Percentage / 100;
  3788. strTaxPercents += percen.LedgerId + ":" + percen.Percentage + ",";
  3789. }
  3790. TaxRateAmount = UnitPrice + TaxRate;
  3791. }
  3792. if (TaxRateAmount == 0) {
  3793. TaxRateAmount = UnitPrice;
  3794. }
  3795. let CompositePrice = Number(TaxRateAmount);
  3796. let CompositePiecePrice = 0;
  3797. if (instance.g_IsEnableCompositePiecePrice) {
  3798. CompositePiecePrice = Number(CompositePiecePriceTaxRate) + PiecePrice;
  3799. }
  3800. LoadedItem.CompositePrice = Number(instance.roundOff(CompositePrice));
  3801. LoadedItem.PiecePrice = Number(instance.roundOff(PiecePrice));
  3802. LoadedItem.CompositePiecePrice = Number(instance.roundOff(CompositePiecePrice));
  3803. if (CartItemIndex != -1) {
  3804. instance.g_CartItems_New[CartItemIndex].CompositePrice = Number(instance.roundOff(CompositePrice));
  3805. instance.g_CartItems_New[CartItemIndex].PiecePrice = Number(instance.roundOff(PiecePrice));
  3806. instance.g_CartItems_New[CartItemIndex].CompositePiecePrice = Number(instance.roundOff(CompositePiecePrice));
  3807. }
  3808. }
  3809. }
  3810. getAmountWithTax(ItemId, Amount) {
  3811. let instance = this;
  3812. let TaxRate = 0, AmountWithTax = 0;
  3813. let LoadedItem = instance.g_LoadedItems.find(x => x.ItemId == ItemId);
  3814. if (LoadedItem != undefined) {
  3815. let taxPercentList = LoadedItem.TaxPercentList;
  3816. if (taxPercentList != null) {
  3817. for (let i = 0; i < taxPercentList.length; i++) {
  3818. let percen = taxPercentList[i];
  3819. TaxRate += Amount * percen.Percentage / 100;
  3820. }
  3821. AmountWithTax = Amount + TaxRate;
  3822. }
  3823. }
  3824. return instance.roundOffIgnoreZerosAfterDecimal(AmountWithTax) + '|' + instance.roundOffIgnoreZerosAfterDecimal(TaxRate);
  3825. }
  3826. getTotals(ModifiedItemId = 0) {
  3827. let instance = this;
  3828. let BranchId = 0;
  3829. let BillingAddressId = 0;
  3830. if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim)
  3831. BranchId = Number($("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billfromaddressid").val());
  3832. else
  3833. BranchId = Number($("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billingaddressid").val());
  3834. $("#" + instance.g_VisibleContainerId).find(".hdn_branchid").val(BranchId);
  3835. if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim)
  3836. BillingAddressId = Number($("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billingaddressid").val());
  3837. else
  3838. BillingAddressId = Number($("#" + instance.g_VisibleContainerId).find(".txtAutoComplete_billfromaddressid").val());
  3839. if (isNaN(BillingAddressId)) {
  3840. let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  3841. let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters;
  3842. if (instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.Sales || instance._order.g_OrderTypeId == Bizgaze.Apps.Transact.Enums.OrderType.PurchaseClaim)
  3843. BillingAddressId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_billingaddressid").Value);
  3844. else
  3845. BillingAddressId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_billfromaddressid").Value);
  3846. }
  3847. let EstimateId = 0;
  3848. let IsSelectAll = false;
  3849. if (instance._order.g_IsPurchasePlanning) {
  3850. if ($("#" + instance.g_VisibleContainerId).find(".chk_PurPlanItem:visible").length != $("#" + instance.g_VisibleContainerId).find(".chk_PurPlanItem:visible:checked").length) {
  3851. $("#" + instance.g_VisibleContainerId).find('#chk_AllItems').prop('checked', false);
  3852. }
  3853. else {
  3854. $("#" + instance.g_VisibleContainerId).find('#chk_AllItems').prop('checked', true);
  3855. }
  3856. let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters;
  3857. let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  3858. if (InputParameters.length > 0 && InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid") != undefined) {
  3859. EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value);
  3860. }
  3861. IsSelectAll = $("#" + instance.g_VisibleContainerId).find('#chk_AllItems').is(':checked');
  3862. }
  3863. else {
  3864. ModifiedItemId = 0;
  3865. }
  3866. if (instance._order.g_IsPointsOrder) {
  3867. let GrossAmount = 0;
  3868. let TotalCartQty = 0;
  3869. instance.g_CartItems_New.forEach(x => GrossAmount += x.UnitPrice * x.BaseQty);
  3870. $("#" + instance.g_VisibleContainerId).find("#lblSummary_GrossAmount, #lblSummary_AssessableTotal, #lblSummary_NetTotal").text(instance.roundOff(GrossAmount));
  3871. $("#" + instance.g_VisibleContainerId).find("#lblSummary_TotalDiscount").text("0.00");
  3872. instance.g_CartItems_New.forEach(x => TotalCartQty += x.BaseQty);
  3873. $("#" + instance.g_VisibleContainerId).find("#OverallOrderQuantity").text(TotalCartQty);
  3874. $("#" + instance.g_VisibleContainerId).find(".netpacks").text(instance.g_CartItems_New.length);
  3875. $("#" + instance.g_VisibleContainerId).find("#PriceDetails_Discount, #PriceDetails_AssblAmount").addClass("hidden");
  3876. }
  3877. else {
  3878. let postdata = {
  3879. OrderItems: instance.g_CartItems_New,
  3880. IsCompositePrice: instance.g_IsEnableCompositePrice,
  3881. IsPiecePrice: instance.g_IsEnablePiecePrice,
  3882. IsTaxInclusive: instance._order.g_IsTaxInclusive == undefined ? false : instance._order.g_IsTaxInclusive,
  3883. IsCalculateTax: instance._order.g_IsCalculateTax == undefined ? false : instance._order.g_IsCalculateTax,
  3884. OrderTypeId: instance._order.g_OrderTypeId,
  3885. BranchId: instance._order.g_BranchId,
  3886. BillingAddressId: BillingAddressId,
  3887. InventoryApplyType: instance._order.g_InventoryApplyType,
  3888. PurchasePlanModifiedItemId: Number(ModifiedItemId),
  3889. IsSelectAll: IsSelectAll,
  3890. EstimateId: EstimateId
  3891. };
  3892. instance.g_AppliedTaxGroups = new Array();
  3893. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getTotals(postdata).then(function (response) {
  3894. instance.g_Totals = response.result;
  3895. let res = instance.g_Totals;
  3896. instance.g_CartItems_New.forEach(c => {
  3897. if (res.ItemWiseTaxGroups != null) {
  3898. let TaxGroupId = res.ItemWiseTaxGroups[c.ItemId];
  3899. c.TaxGroupId = TaxGroupId;
  3900. }
  3901. c.RowTotal = res.OrderItems.find(x => x.ItemId == c.ItemId).RowTotal;
  3902. c.RowDiscount = res.OrderItems.find(x => x.ItemId == c.ItemId).RowDiscount;
  3903. c.TaxTotal = res.OrderItems.find(x => x.ItemId == c.ItemId).TaxTotal;
  3904. });
  3905. if (instance.roundOff(res.TotalScrapDiscountAmount) > 0)
  3906. $("#" + instance.g_VisibleContainerId).find("#div_ScrapDiscount").removeClass("hidden");
  3907. else
  3908. $("#" + instance.g_VisibleContainerId).find("#div_ScrapDiscount").addClass("hidden");
  3909. $("#" + instance.g_VisibleContainerId).find('#lblSummary_GrossAmount, .labelSection_Gross_Value').text(instance.roundOff(res.GrossAmount));
  3910. $("#" + instance.g_VisibleContainerId).find('#lblSummary_TotalDiscount, .labelSection_Discount_Value').text(instance.roundOff(res.TotalDiscount));
  3911. $("#" + instance.g_VisibleContainerId).find('#lblSummary_NetTotal, .labelSection_Total_Value').text(instance.roundOff(res.NetTotal));
  3912. $("#" + instance.g_VisibleContainerId).find('#lblSummary_AssessableTotal').text(instance.roundOff(res.AssessableAmount));
  3913. $("#" + instance.g_VisibleContainerId).find('#lblSummary_TaxTotal').text(instance.roundOff(res.TotalTax));
  3914. $("#" + instance.g_VisibleContainerId).find('#lblSummary_ScrapDiscountAmount').text('-' + (instance.roundOff(res.TotalScrapDiscountAmount)));
  3915. $("#" + instance.g_VisibleContainerId).find(".hdn_scrapdiscountamount").val(instance.roundOff(res.TotalScrapDiscountAmount));
  3916. if (instance._order.g_IsPurchasePlanning) {
  3917. $("#" + instance.g_VisibleContainerId).find(".labelSection_Gross_Value, .labelSection_Discount_Value, .labelSection_Total_Value, .labelSection_GrossAmount, .labelSection_DiscountAmount, .labelSection_NetTotal").addClass("font-weight-bold").addClass("col-sm-12").addClass("text-center");
  3918. if (instance.g_CartItems_New.length == 0) {
  3919. $("#" + instance.g_VisibleContainerId).find("#btnDynamicSave").addClass("disabled").css("cursor", "not-allowed");
  3920. }
  3921. else {
  3922. $("#" + instance.g_VisibleContainerId).find("#btnDynamicSave").removeClass("disabled").css("cursor", "auto");
  3923. }
  3924. }
  3925. $("#" + instance.g_VisibleContainerId).find('#OverallOrderQuantity').text(instance.roundOffIgnoreZerosAfterDecimal(res.TotalQuantity, 2));
  3926. $("#" + instance.g_VisibleContainerId).find(".netpacks").text(instance.g_CartItems_New.length);
  3927. });
  3928. }
  3929. }
  3930. getPurchasePlanTotals(OnlyTotals, IsChangedSelectAllChkbx) {
  3931. let instance = this;
  3932. if ($("#" + instance.g_VisibleContainerId).find(".chk_PurPlanItem:visible").length != $("#" + instance.g_VisibleContainerId).find(".chk_PurPlanItem:visible:checked").length) {
  3933. $("#" + instance.g_VisibleContainerId).find('#chk_AllItems').prop('checked', false);
  3934. }
  3935. else {
  3936. $("#" + instance.g_VisibleContainerId).find('#chk_AllItems').prop('checked', true);
  3937. }
  3938. let EstimateId = 0;
  3939. let IsSelectAll = false;
  3940. if (instance._order.g_IsPurchasePlanning) {
  3941. let InputParameters = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters;
  3942. let InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  3943. if (InputParameters.length > 0 && InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid") != undefined) {
  3944. EstimateId = Number(InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_estimateid").Value);
  3945. }
  3946. IsSelectAll = $("#" + instance.g_VisibleContainerId).find('#chk_AllItems').is(':checked');
  3947. }
  3948. let postdata = {
  3949. IsChangedSelectAll: IsChangedSelectAllChkbx,
  3950. IsConfirmed: IsSelectAll,
  3951. IsSelectAll: IsSelectAll,
  3952. EstimateId: EstimateId,
  3953. OnlyTotals: OnlyTotals
  3954. };
  3955. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getPurchasePlanTotals(postdata).then(function (response) {
  3956. instance.g_Totals = response.result;
  3957. let res = instance.g_Totals;
  3958. if (instance.roundOff(res.TotalScrapDiscountAmount) > 0)
  3959. $("#" + instance.g_VisibleContainerId).find("#div_ScrapDiscount").removeClass("hidden");
  3960. else
  3961. $("#" + instance.g_VisibleContainerId).find("#div_ScrapDiscount").addClass("hidden");
  3962. $("#" + instance.g_VisibleContainerId).find('#lblSummary_GrossAmount, .labelSection_Gross_Value').text(instance.roundOff(res.GrossAmount));
  3963. $("#" + instance.g_VisibleContainerId).find('#lblSummary_TotalDiscount, .labelSection_Discount_Value').text(instance.roundOff(res.TotalDiscount));
  3964. $("#" + instance.g_VisibleContainerId).find('#lblSummary_NetTotal, .labelSection_Total_Value').text(instance.roundOff(res.AssessableAmount));
  3965. });
  3966. }
  3967. getOrderItems(OrderId = 0) {
  3968. let instance = this;
  3969. let ItemList = new Array();
  3970. for (let c = 0; c < instance.g_CartItems_New.length; c++) {
  3971. let orderItemIndex = c;
  3972. let CartItem = instance.g_CartItems_New[c];
  3973. let FocItemIds = "";
  3974. instance.g_CartItems_New.filter(z => z.RefItemIds.indexOf(CartItem.ItemId.toString()) > -1).forEach(x => {
  3975. FocItemIds += x.ItemId + "|";
  3976. });
  3977. if (CartItem.IsFocItem || CartItem.Quantity == 0) {
  3978. continue;
  3979. }
  3980. let Quantity = CartItem.Quantity;
  3981. var Category_Id = $($(".cartitem-" + CartItem.ItemId).parentsUntil("cartItemsSortable")[0]).attr("id");
  3982. if (Category_Id != undefined) {
  3983. Category_Id = Category_Id.replace("catItemsSortable_", "");
  3984. }
  3985. let CategoryName = $("#catTitleSpan_" + Category_Id).text();
  3986. ItemList.push({
  3987. OrderItemId: CartItem.OrderItemId,
  3988. OrderId: OrderId,
  3989. OrderItemIndex: orderItemIndex,
  3990. ItemId: CartItem.ItemId,
  3991. ItemName: CartItem.ItemName,
  3992. UnitPrice: CartItem.UnitPriceWithOutTax,
  3993. PriceListId: CartItem.PriceListId,
  3994. ExpectedPrice: CartItem.ExpectedPrice,
  3995. Quantity: Quantity,
  3996. ConversionQuantity: CartItem.ConversionQuantity,
  3997. TaxGroupId: CartItem.TaxGroupId,
  3998. TaxGroupName: CartItem.TaxGroupName,
  3999. Description: CartItem.Description,
  4000. DiscountPercent: CartItem.DiscountPercent,
  4001. DiscountAmount: CartItem.DiscountAmount,
  4002. DiscountValue: CartItem.DiscountValue,
  4003. DiscountGroupId: CartItem.DiscountGroupId,
  4004. RefNo: "",
  4005. AvailableQty: CartItem.AvailableQuantity,
  4006. ExchangeDC: CartItem.ExchangeDC,
  4007. HideOnInvoice: false,
  4008. Packs: CartItem.Packs,
  4009. Pieces: CartItem.Pieces,
  4010. IsAfterTax: CartItem.IsAfterTax,
  4011. OptOutAmount: CartItem.optoutAmount,
  4012. OptOutCampaignGroupId: CartItem.optoutOfferGroupId,
  4013. IsFoc: CartItem.IsFocItem,
  4014. OrderFromEstimate: false,
  4015. PriceTypeId: Number(instance.g_PriceTypeId),
  4016. RefOrderItemId: Number(CartItem.RefOrderItemId),
  4017. RefItemIds: CartItem.RefItemIds,
  4018. FocItemIds: FocItemIds,
  4019. AlternateUnitId: CartItem.SelectedUnitId,
  4020. DefaultSize: CartItem.DefaultSize,
  4021. SKU: CartItem.SKU,
  4022. RowTotal: CartItem.RowTotal,
  4023. RowDiscount: CartItem.RowDiscount,
  4024. TaxTotal: CartItem.TaxTotal,
  4025. CategoryName: CategoryName
  4026. });
  4027. }
  4028. return ItemList;
  4029. }
  4030. getItemPreview(Itemid) {
  4031. var instance = this;
  4032. instance.fileCacheHelper.loadJsFile('apps/transact/controls/itemdetails/itemscarousel.js', function () {
  4033. instance.navigationHelper.popup(Itemid, '', Bizgaze.Apps.Transact.Controls.ItemDetails.ItemsCarousel.Instance(), null, Unibase.Platform.Helpers.Size.Medium);
  4034. });
  4035. }
  4036. static Instance() {
  4037. if (this.instance === undefined) {
  4038. this.instance = new OrderItems();
  4039. }
  4040. return this.instance;
  4041. }
  4042. }
  4043. Controls.OrderItems = OrderItems;
  4044. })(Controls = Transact.Controls || (Transact.Controls = {}));
  4045. })(Transact = Apps.Transact || (Apps.Transact = {}));
  4046. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  4047. })(Bizgaze || (Bizgaze = {}));
  4048. var Bizgaze;
  4049. (function (Bizgaze) {
  4050. let Apps;
  4051. (function (Apps) {
  4052. let Transact;
  4053. (function (Transact) {
  4054. let Components;
  4055. (function (Components) {
  4056. class OrderFilter extends Unibase.Platform.Core.BaseComponent {
  4057. constructor() {
  4058. super(...arguments);
  4059. this.g_TagArray = [];
  4060. this.g_ClearingTags = "";
  4061. this.g_ContainerId = "";
  4062. this.g_Tags = "";
  4063. this.g_OnlyFilters = false;
  4064. this.g_TagCategoryId = 0;
  4065. this.g_LobId = 0;
  4066. }
  4067. cssFiles() {
  4068. return [];
  4069. }
  4070. jsFiles() {
  4071. var jsFiles = ['apps/crm/lobs/managers/lobmanager.js', 'apps/transact/managers/inventory/itemmanager.js'];
  4072. return jsFiles;
  4073. }
  4074. html(id, containerid) {
  4075. var instance = this;
  4076. instance.g_ContainerId = containerid;
  4077. var html = `<header class="b-b bg-white modal-header pt-10 pb-10">
  4078. <strong class="text-dark titlename">Filters</strong>
  4079. <div class="btn-group ml-auto"> <a class="btn btn-sm"><i class="ti-help-alt" title="help" href="" target="_blank"></i></a></div>
  4080. </header>
  4081. <div style="overflow-x:hidden;" class="scrollable">
  4082. <div class="card">
  4083. <div class="card-body">
  4084. <div class="divTagList"></div>
  4085. </div>
  4086. </div>
  4087. </div>
  4088. <footer class="bg-white modal-footer pt-10 pb-10">
  4089. <a href="javascript:;" id="btn_CancelFilter" class="btn btn-light btn-sm mr-auto"> Close </a>
  4090. <a href="javascript:;" id="btn_ApplyFilter" class="btn btn-primary btn-sm">Apply</a>
  4091. <a href="javascript:;" id="btn_ClearFilter" class="btn btn-primary btn-sm">Clear</a>
  4092. </footer>`;
  4093. return html;
  4094. }
  4095. load(id, containerid, callback) {
  4096. var instance = this;
  4097. instance.g_LobId = Number($(".txtAutoComplete_LobId").val());
  4098. instance.categoryTagItem();
  4099. if (id == "POS") {
  4100. instance.g_order = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance();
  4101. instance.g_orderItem = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance();
  4102. }
  4103. else {
  4104. instance.g_order = Bizgaze.Apps.Transact.Controls.Order.Instance();
  4105. instance.g_orderItem = Bizgaze.Apps.Transact.Controls.OrderItems.Instance();
  4106. }
  4107. if (isNaN(instance.g_LobId)) {
  4108. instance.g_LobId = instance.g_order.g_LobId;
  4109. }
  4110. $('#btn_CancelFilter').click(function () {
  4111. for (var i = 0; i < instance.g_TagArray.length; i++) {
  4112. instance.g_ClearingTags += instance.g_TagArray[i].TagId + "|";
  4113. }
  4114. instance.g_ClearingTags = instance.g_ClearingTags.replace(/\:$/, '');
  4115. instance.g_Tags = instance.g_ClearingTags;
  4116. instance.filterItemsByTags(instance.g_ClearingTags, false);
  4117. });
  4118. $('#btn_ClearFilter').click(function () {
  4119. instance.g_orderItem.g_IsFilterApplied = false;
  4120. instance.g_orderItem.g_FilteredTags = '';
  4121. instance.clearAll();
  4122. });
  4123. $('#btn_ApplyFilter').click(function () {
  4124. instance.g_orderItem.g_IsFilterApplied = true;
  4125. instance.showFilteredItems();
  4126. });
  4127. }
  4128. bindCustomerTags(id = "") {
  4129. var instance = this;
  4130. if (id == "POS") {
  4131. instance.g_order = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance();
  4132. instance.g_orderItem = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance();
  4133. }
  4134. else {
  4135. instance.g_order = Bizgaze.Apps.Transact.Controls.Order.Instance();
  4136. instance.g_orderItem = Bizgaze.Apps.Transact.Controls.OrderItems.Instance();
  4137. }
  4138. var TagGroupId = instance.g_order.g_TagGroupId;
  4139. var OrganizationId = instance.g_order.g_OrganizationId;
  4140. Unibase.Platform.Forms.Managers.TagManager.Instance().GetTagsByRefId(OrganizationId, TagGroupId).then(function (response) {
  4141. var data = response.result;
  4142. var options = '';
  4143. var tags = '';
  4144. instance.g_TagArray = [];
  4145. for (var i = 0; i < data.length; i++) {
  4146. if (data[i] != undefined) {
  4147. instance.g_TagArray.push({ TagId: data[i].TagId, TagName: data[i].TagName, ParentId: data[i].ParentRootId });
  4148. options += data[i].TagId + "|";
  4149. }
  4150. }
  4151. if (options != '') {
  4152. options = options.replace(/\|$/, '');
  4153. tags = options;
  4154. }
  4155. if (tags != '') {
  4156. tags = tags.replace(/\:$/, '');
  4157. }
  4158. instance.g_Tags = tags;
  4159. instance.filterItemsByTags(tags, true);
  4160. if (Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_TagArray.length != 0) {
  4161. $("#ItemLoadType option[value='1']").remove();
  4162. instance.g_OnlyFilters = true;
  4163. }
  4164. });
  4165. }
  4166. addTagItem(TagGroupId) {
  4167. var instance = this;
  4168. if (TagGroupId != 0) {
  4169. Unibase.Platform.Forms.Managers.TagManager.Instance().getTagParentsByCategoryId(Number(instance.g_TagCategoryId), TagGroupId).then(function (response) {
  4170. var taghtml = '';
  4171. var disabled = "";
  4172. if (Bizgaze.Apps.Transact.Components.OrderFilter.Instance().g_OnlyFilters) {
  4173. disabled = "disabled";
  4174. $("#btn_ApplyOrderFilter, #btn_ClearOrderFilter").addClass("hidden");
  4175. }
  4176. for (var i = 0; i < response.result.length; i++) {
  4177. var tagName = response.result[i].TagName;
  4178. if (i % 2 == 0) {
  4179. taghtml += '<div class="row"><div class="col-sm-12">';
  4180. }
  4181. taghtml += '<div class="col-sm-6 lobTagItems">';
  4182. taghtml += '<div class="floating-label-form-group floating-label-form-group-with-value no-border" style="border-bottom:0;"><label>' + tagName + '</label>' +
  4183. '<select multiple="multiple" style="width:100%" class="txtTagsSelect2_' + i + ' " id="txtBizgazeNotifications_Tags_' + i + '" data-id=' + i + ' ' + disabled + ' > </select>' +
  4184. '<input type="hidden" class="hfTagCloud_ParentTagId-' + i + '" value="' + response.result[i].TagId + '" />' +
  4185. '</div></div>';
  4186. if (i % 2 == 1) {
  4187. taghtml += '</div></div>';
  4188. }
  4189. }
  4190. if (response.result.length == 0) {
  4191. taghtml += '' + '<h5><span">No Tags Assigned For This Lob.</span></h5>';
  4192. }
  4193. $('.divTagList').html(taghtml);
  4194. if (response.result.length != 0) {
  4195. instance.refreshTags();
  4196. }
  4197. });
  4198. }
  4199. }
  4200. refreshTags() {
  4201. var instance = this;
  4202. var y = 0;
  4203. var lobid = $(".txtAutoComplete_lobid").val();
  4204. var categoryId = instance.g_TagCategoryId;
  4205. var PARENTID = "";
  4206. let serviceurl = "apis/v4/unibase/platform/forms/autotagsforassignment";
  4207. serviceurl = _appsettings.server_url() + (serviceurl.startsWith('/') ? serviceurl : ('/' + serviceurl));
  4208. $(".lobTagItems").each(function () {
  4209. var parentId = $(this).find(".hfTagCloud_ParentTagId-" + y).val();
  4210. PARENTID += parentId + ",";
  4211. if (parentId != undefined) {
  4212. var Tags = [];
  4213. var Ids = [];
  4214. if (instance.g_TagArray != undefined && instance.g_TagArray != '') {
  4215. for (var i = 0; i < instance.g_TagArray.length; i++) {
  4216. var Tag = instance.g_TagArray[i];
  4217. if (parentId == Tag.ParentId) {
  4218. Tags.push({ id: Tag.TagId, text: Tag.TagName });
  4219. Ids.push(Tag.TagId);
  4220. }
  4221. }
  4222. }
  4223. var Parameters = [
  4224. { ColumnName: 'LobId', Value: lobid },
  4225. { ColumnName: 'CategoryId', Value: categoryId },
  4226. { ColumnName: 'ParentId', Value: PARENTID },
  4227. ];
  4228. var ColumnName = "", Value = "";
  4229. if (Parameters != null) {
  4230. ColumnName = Parameters.map(function (item) { return item.ColumnName; }).toString();
  4231. Value = Parameters.map(function (item) { return item.Value + "|"; }).toString();
  4232. }
  4233. $(".txtTagsSelect2_" + y).select2({
  4234. placeholder: "Select",
  4235. data: Tags,
  4236. ajax: {
  4237. url: serviceurl,
  4238. contentType: 'application/json',
  4239. dataType: 'json',
  4240. type: "POST",
  4241. traditional: true,
  4242. crossDomain: true,
  4243. async: true,
  4244. data: function (params) {
  4245. var y = $(this).attr("id").replace("txtBizgazeNotifications_Tags_", "");
  4246. parentId = $(".hfTagCloud_ParentTagId-" + y).val();
  4247. var ParticipantsCount = new Array();
  4248. var Participants = "";
  4249. if ($(".txtTagsSelect2_" + Number($(this).attr('data-id'))).val().toString() != "") {
  4250. var Participant = $(".txtTagsSelect2_" + Number($(this).attr('data-id'))).val().toString();
  4251. ParticipantsCount = Participant.split(',');
  4252. for (var i = 0; i < ParticipantsCount.length; i++) {
  4253. Participants += "|" + ParticipantsCount[i];
  4254. }
  4255. Participants;
  4256. }
  4257. var Term = params.term != undefined ? params.term : "";
  4258. var postData = {
  4259. DocPropertyId: 0,
  4260. ColumnName: ColumnName,
  4261. FormPropertyId: Number($(this).attr('data-id')),
  4262. Value: Value,
  4263. bindedData: Participants.substring(1, Participants.length),
  4264. term: Term,
  4265. TagGroupId: Number(instance.g_order.g_TagGroupId),
  4266. TagCatagoryId: Number(categoryId),
  4267. TagId: Number(parentId),
  4268. };
  4269. return JSON.stringify(postData);
  4270. },
  4271. processResults: function (data) {
  4272. var json_data = JSON.parse(data.result);
  4273. var cols = [];
  4274. for (let i = 0; i < json_data.length; i++) {
  4275. var ids = {
  4276. id: json_data[i].Value,
  4277. text: json_data[i].DisplayText
  4278. };
  4279. cols.push(ids);
  4280. }
  4281. return { results: cols };
  4282. },
  4283. beforeSend: function (xhr) {
  4284. if (Unibase.Platform.Membership.Infos.Identity.getCurrentUser() !== undefined && Unibase.Platform.Membership.Infos.Identity.getCurrentUser() !== null) {
  4285. xhr.setRequestHeader('Authorization', 'Basic ' + Unibase.Platform.Membership.Infos.Identity.getCurrentUser().sessionId);
  4286. xhr.setRequestHeader('geoposition', Unibase.Platform.Membership.Infos.Identity.getCurrentUser().latd + ':' + Unibase.Platform.Membership.Infos.Identity.getCurrentUser().lgId);
  4287. }
  4288. },
  4289. },
  4290. });
  4291. jQuery(".txtTagsSelect2_" + y).val(Ids).trigger('change');
  4292. }
  4293. y++;
  4294. });
  4295. y = 0;
  4296. }
  4297. categoryTagItem() {
  4298. var instance = this;
  4299. Unibase.Platform.Forms.Managers.TagManager.Instance().getTagCategoryByName("Items").then(function (response) {
  4300. var data = response.result;
  4301. instance.g_TagCategoryId = data.TagCategoryId;
  4302. var TagGroupId = instance.g_order.g_TagGroupId;
  4303. if (TagGroupId != null && TagGroupId != 0) {
  4304. instance.addTagItem(TagGroupId);
  4305. }
  4306. });
  4307. }
  4308. showFilteredItems() {
  4309. var instance = this;
  4310. var tags = '';
  4311. var select2Id = 0;
  4312. instance.g_TagArray = [];
  4313. $(".lobTagItems").each(function () {
  4314. var data = $(this).find('#txtBizgazeNotifications_Tags_' + select2Id + '').select2('data');
  4315. var parentId = $(this).find(".hfTagCloud_ParentTagId-" + select2Id).val();
  4316. if (data.length > 0) {
  4317. var options = '';
  4318. for (var i = 0; i < data.length; i++) {
  4319. if (data[i] != '000' && data[i] != undefined) {
  4320. instance.g_TagArray.push({ TagId: data[i].id, TagName: data[i].text, ParentId: parentId });
  4321. options += data[i].id + "|";
  4322. }
  4323. }
  4324. if (options != '') {
  4325. options = options.replace(/\|$/, '');
  4326. tags += options + "|";
  4327. }
  4328. }
  4329. select2Id++;
  4330. });
  4331. if (tags != '') {
  4332. tags = tags.replace(/\:$/, '');
  4333. }
  4334. instance.g_Tags = tags;
  4335. instance.filterItemsByTags(tags, false);
  4336. }
  4337. clearAll() {
  4338. var select2Id = 0;
  4339. $(".lobTagItems").each(function () {
  4340. $(this).find('#txtBizgazeNotifications_Tags_' + select2Id + '').val(null).trigger('change');
  4341. select2Id++;
  4342. });
  4343. }
  4344. filterItemsByTags(Tags, Ispagination) {
  4345. var instance = this;
  4346. instance.g_order.g_LoadOffersOnly = false;
  4347. if (Tags == "" || Tags == null || Tags == undefined) {
  4348. if (instance.g_order.g_IsPurchasePlanning)
  4349. instance.g_orderItem.loadPurchasePlanItems('');
  4350. else
  4351. instance.g_orderItem.loadItems($("#txt_SearchItem").val());
  4352. if (instance.g_ContainerId != "") {
  4353. if ($('#' + instance.g_ContainerId).length > 0) {
  4354. $('#' + instance.g_ContainerId).modal('hide');
  4355. }
  4356. }
  4357. $("#ItemLoadType").val(1);
  4358. if (!Ispagination) {
  4359. $('#' + instance.g_ContainerId).modal('hide');
  4360. $('#' + instance.g_ContainerId).remove();
  4361. }
  4362. }
  4363. else {
  4364. var SearchTerm = $("#txt_SearchItem").val();
  4365. if (SearchTerm == "")
  4366. SearchTerm = null;
  4367. instance.g_orderItem.g_FilteredTags = Tags;
  4368. var contactId = instance.g_order.g_OrganizationId;
  4369. if (contactId == 0)
  4370. contactId = instance.g_order.g_OrgContactId;
  4371. instance.fileCacheHelper.loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
  4372. instance.g_Tags = Tags;
  4373. instance.g_orderItem.loadItems($("#txt_SearchItem").val());
  4374. $("#ItemLoadType").val(3);
  4375. if (!Ispagination) {
  4376. $('#' + instance.g_ContainerId).modal('hide');
  4377. $('#' + instance.g_ContainerId).remove();
  4378. }
  4379. });
  4380. }
  4381. }
  4382. static Instance() {
  4383. if (this.instance === undefined) {
  4384. this.instance = new OrderFilter();
  4385. }
  4386. return this.instance;
  4387. }
  4388. }
  4389. Components.OrderFilter = OrderFilter;
  4390. })(Components = Transact.Components || (Transact.Components = {}));
  4391. })(Transact = Apps.Transact || (Apps.Transact = {}));
  4392. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  4393. })(Bizgaze || (Bizgaze = {}));
  4394. var Unibase;
  4395. (function (Unibase) {
  4396. let Platform;
  4397. (function (Platform) {
  4398. let Helpers;
  4399. (function (Helpers) {
  4400. class PrintHelper {
  4401. printPopup(PrintHtml) {
  4402. if (isMobileApp()) {
  4403. Unibase.Platform.Helpers.MobileHelper.Instance().previewHtml(PrintHtml);
  4404. }
  4405. else {
  4406. var mywindow = window.open('', 'my Print', 'height=400,width=850');
  4407. var content = '<html><head><title>Print</title><link rel="stylesheet" href="lib/bizgaze/print.css" /><link rel="stylesheet" href="lib/bootstrap/bootstrap-theme.min.css" /></head><body>';
  4408. content += PrintHtml;
  4409. content += "<script>print();</script>";
  4410. content += '</body></html>';
  4411. mywindow.document.write(content);
  4412. }
  4413. return true;
  4414. }
  4415. static Instance() {
  4416. if (this.instance === null || this.instance === undefined)
  4417. this.instance = new PrintHelper();
  4418. return this.instance;
  4419. }
  4420. }
  4421. Helpers.PrintHelper = PrintHelper;
  4422. })(Helpers = Platform.Helpers || (Platform.Helpers = {}));
  4423. })(Platform = Unibase.Platform || (Unibase.Platform = {}));
  4424. })(Unibase || (Unibase = {}));
  4425. var Bizgaze;
  4426. (function (Bizgaze) {
  4427. let Apps;
  4428. (function (Apps) {
  4429. let Transact;
  4430. (function (Transact) {
  4431. let Components;
  4432. (function (Components) {
  4433. let Invoices;
  4434. (function (Invoices) {
  4435. class ItemOfferSelection extends Unibase.Platform.Core.BaseComponent {
  4436. constructor() {
  4437. super(...arguments);
  4438. this.Bizgaze_Transact_Selected_Plan = new Array();
  4439. this.g_Selected_Plan = new Array();
  4440. this.OfferIds = [];
  4441. }
  4442. jsFiles() {
  4443. return ['platform/core/helpers/numberhelper/numberhelper.js', 'apps/transact/managers/invoicemanager.js', 'apps/transact/controls/invoices/pos.component.js'];
  4444. }
  4445. cssFiles() {
  4446. return [];
  4447. }
  4448. html() {
  4449. let html = '<form id="frm_Bizgazetransact_ItemOfferSelection" method="post" data-validate="parsley"><div class="b-b bg-white modal-header"><strong class="text-dark titlename">Offer of <strong id="sg_item"></strong></strong></div><div data-simplebar class="bg-light simple-scroll-bar control-sorting modal-body"><div class=""><div class="col-sm-12"><div class="li_Invoice_OfferItem_header"></div><ul><li class="hidden list-group-item Plan_Vlm_row" id ="li_Invoice_OfferItem"> </li> <div class="Offer_Header"> </ul> </div></div></div><div class="bg-white modal-footer"><a href="javascript:;" class="btn btn-light btn-sm mr-auto btn_close" id="offer_btnclose">Close</a><span class="mr-auto" id="spn_Quantity"></span> <a href="javascript:;" class="btn btn-primary btn-sm btn_pos_apply disabled" style="cursor:not-allowed" id ="btn_Apply">Apply</a></div></form>';
  4450. return html;
  4451. }
  4452. load(item) {
  4453. var instance = this;
  4454. instance.Bizgaze_Transact_Selected_Plan = new Array();
  4455. $(".btn_close").click(function () {
  4456. instance.navigationHelper.closePopUp();
  4457. });
  4458. }
  4459. PlanSelection(Volume, value, DiscountType, PlanVolumeId, ItemId, len, focItemId) {
  4460. var instance = this;
  4461. $('.Plan_Vlm_row').css('background-color', '');
  4462. $('#spn_Quantity').text(Volume);
  4463. $("#frm_Bizgazetransact_ItemOfferSelection").find("#btn_Apply").removeAttr("style").removeClass("disabled");
  4464. instance.Bizgaze_Transact_Selected_Plan = new Array();
  4465. instance.Bizgaze_Transact_Selected_Plan.push({
  4466. Volume: Volume, value: value, DiscountType: DiscountType, PlanVolumeId: PlanVolumeId, ItemId: ItemId, focItemId: focItemId
  4467. });
  4468. instance.g_Selected_Plan.push({
  4469. Volume: Volume, value: value, DiscountType: DiscountType, PlanVolumeId: PlanVolumeId, ItemId: ItemId, focItemId: focItemId
  4470. });
  4471. }
  4472. LoadOfferItems(OrganizationId, ItemId, ItemName, InvoiceApplyType, element, Type) {
  4473. var instance = this;
  4474. instance.Bizgaze_Transact_Selected_Plan = new Array();
  4475. $('#sg_item').text(ItemName);
  4476. ItemOfferSelection.Instance().GetPlanVolume(OrganizationId, ItemId, InvoiceApplyType, Type);
  4477. $('#btn_Apply').click(function () {
  4478. if (Type == 'Invoice') {
  4479. ItemOfferSelection.Instance().Apply(element);
  4480. }
  4481. else if (Type == 'Order') {
  4482. instance.navigationHelper.closePopUp();
  4483. if (instance.Bizgaze_Transact_Selected_Plan.length > 0) {
  4484. Bizgaze.Apps.Transact.Controls.OrderItems.Instance().applyOffer(instance.Bizgaze_Transact_Selected_Plan);
  4485. }
  4486. }
  4487. else if (Type == 'Estimate') {
  4488. instance.navigationHelper.closePopUp();
  4489. if (instance.Bizgaze_Transact_Selected_Plan.length > 0) {
  4490. Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().applyOffer(instance.Bizgaze_Transact_Selected_Plan);
  4491. }
  4492. }
  4493. else if (Type == 'Opportunity') {
  4494. instance.navigationHelper.closePopUp();
  4495. if (instance.Bizgaze_Transact_Selected_Plan.length > 0) {
  4496. Bizgaze.Apps.Transact.Controls.OpportunityItem.Instance().applyOffer(instance.Bizgaze_Transact_Selected_Plan);
  4497. }
  4498. }
  4499. else if (Type == 'POS_Order') {
  4500. let elem = $(".variant-addeditem-" + ItemId);
  4501. let html = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().getInventoryDesign(ItemId, false, 0, 0, "ApplyOffer");
  4502. $(elem).find(".InventoryTypesTextboxes").html(html);
  4503. Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().allItemEvents(elem);
  4504. instance.navigationHelper.closePopUp();
  4505. if (instance.Bizgaze_Transact_Selected_Plan.length > 0) {
  4506. Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().applyOffer(instance.Bizgaze_Transact_Selected_Plan);
  4507. }
  4508. }
  4509. else if (Type == 'Pos') {
  4510. instance.navigationHelper.closePopUp();
  4511. if (instance.Bizgaze_Transact_Selected_Plan.length > 0) {
  4512. Bizgaze.Apps.Transact.Controls.Pos.Instance().applyOffer(instance.Bizgaze_Transact_Selected_Plan);
  4513. }
  4514. }
  4515. });
  4516. }
  4517. GetPlanVolume(OrganizationId, ItemId, InvoiceApplyType, Type) {
  4518. let instance = this;
  4519. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getPlanVolume(ItemId, OrganizationId, InvoiceApplyType).then(function (result) {
  4520. instance.OfferIds = [];
  4521. for (var i = 0; i < result.result.length; i++) {
  4522. ItemOfferSelection.Instance().ShowItemOffers(result.result[i], ItemId, Type);
  4523. }
  4524. });
  4525. }
  4526. ShowItemOffers(data, ItemId, Type) {
  4527. let instance = this;
  4528. var value;
  4529. if (data.DiscountType == 1) {
  4530. value = data.PayoutValue;
  4531. }
  4532. else {
  4533. if (data.DiscountType == 2) {
  4534. value = data.PayoutPercent;
  4535. }
  4536. else {
  4537. if (data.DiscountType == 3) {
  4538. value = data.OPayoutValue;
  4539. }
  4540. }
  4541. }
  4542. var len = $('.Plan_Vlm_row').length;
  4543. var html_header = '<div class="card col-sm-12 Offer_Header pt-20" id="Offer_Header_' + data.OfferId + '"> <div class="pl-0 pb-2"> <input type="hidden" class="hf_Pln_Vlm_OfferId" value="' + data.OfferId + '"/> <span class="list-item-main-title font-weight-600 font-20">' + data.OfferName + '</span> <span class="text-dark"> - ' + data.SchemeName + '</span></div>';
  4544. var html = '<div class="card card-body pa-15 Card_Plan_Vlm_row Card_Plan_Vlm_row_' + data.PlanVolumeId + '" id="Card_Plan_Vlm_row_' + data.PlanVolumeId + '"> <div class="text-dark plan_Name font-weight-600 border-bottom border-2 pb-2">' + data.PlanName + ' </div> <div class="main-heading py-2">';
  4545. var html_body = '<li class="Plan_Vlm_row Plan_Vlm_row_' + data.PlanVolumeId + '">' +
  4546. '<a href="javascript:;" class="text-dark">' +
  4547. '<div class="" id="div_PlanVlm_' + len + '">' +
  4548. '<div class="d-flex justify-content-between align-items-center w-100" style="line-height: 0.8;"><div class="biz-highlight-text-color font-36 w-100 font-weight-600"><span id="spn_Discount"></span> <span id="spn_DiscountType" class="font-12"> </span> <span class="font-12 spn_off">OFF</span></div><div class="text-success font-14 font-widget-300 px-2 offers_applied" id="li_Pln_Vlm' + len + '"><u>Apply</u></div></div><div class="font-weight-600 w-100">On Purchase of Min-Qty : ' + data.Volume + '</div>' +
  4549. '</div></a></li></div>';
  4550. let offerIndex = instance.OfferIds.findIndex(x => x.OfferId == data.OfferId);
  4551. if (offerIndex == -1) {
  4552. instance.OfferIds.push({ OfferId: data.OfferId });
  4553. html = html_header + html + html_body;
  4554. html += '</div>';
  4555. $('.Offer_Header:last').after(html);
  4556. }
  4557. else {
  4558. html += html_body;
  4559. $('#Offer_Header_' + data.OfferId).append(html);
  4560. }
  4561. var ss = data.PlanName;
  4562. $("#li_Pln_Vlm" + len).click(function () {
  4563. let Clicked_Id = $(this).attr("id");
  4564. var focElement = document.getElementById("li_Pln_Vlm" + len);
  4565. var focItemIdElement = focElement.querySelector(".selectedfocitem");
  4566. var focItemId = "0";
  4567. if (focItemIdElement != null) {
  4568. focItemId = focItemIdElement.id;
  4569. }
  4570. let checkstatus = $(this).find("u").text();
  4571. let AppliedPlanVolumeId = $(this).parents(".Card_Plan_Vlm_row").attr("id").replace("Card_Plan_Vlm_row_", "");
  4572. if (checkstatus == "Apply") {
  4573. $(".Card_Plan_Vlm_row").removeAttr("style");
  4574. var offerItemIndex = instance.Bizgaze_Transact_Selected_Plan.findIndex(x => x.ItemId == ItemId);
  4575. if (offerItemIndex != -1) {
  4576. instance.Bizgaze_Transact_Selected_Plan.splice(offerItemIndex, 1);
  4577. }
  4578. var sp_ItemIndex = instance.g_Selected_Plan.findIndex(x => x.ItemId == ItemId);
  4579. if (offerItemIndex != -1) {
  4580. instance.g_Selected_Plan.splice(sp_ItemIndex, 1);
  4581. }
  4582. $(".Plan_Vlm_row").find(".offers_applied").find("u").text("Apply").addClass("text-primary").removeClass("text-danger");
  4583. instance.HighlightAppliedPlans(AppliedPlanVolumeId, ItemId, true);
  4584. ItemOfferSelection.Instance().PlanSelection(data.Volume, value, data.DiscountType, data.PlanVolumeId, ItemId, len, Number(focItemId));
  4585. }
  4586. else {
  4587. var msg = 'Do you what to remove Applied Offer';
  4588. bootbox.confirm({
  4589. message: msg,
  4590. closeButton: false,
  4591. buttons: {
  4592. confirm: {
  4593. label: 'Remove',
  4594. className: 'btn-success'
  4595. },
  4596. cancel: {
  4597. label: 'Cancel',
  4598. className: 'btn-danger'
  4599. }
  4600. },
  4601. callback: function (result) {
  4602. if (result) {
  4603. instance.UnHighlightPlan(AppliedPlanVolumeId, ItemId, Type);
  4604. $("#spn_Quantity").text("");
  4605. }
  4606. else {
  4607. $('#modal_popup_EditLineItem').modal('hide');
  4608. bootbox.hideAll();
  4609. return false;
  4610. }
  4611. }
  4612. });
  4613. }
  4614. });
  4615. if (value > 0) {
  4616. $("#div_PlanVlm_" + len).find('#spn_Discount').text(value);
  4617. if (data.DiscountType == 2) {
  4618. $("#div_PlanVlm_" + len).find('#spn_DiscountType').text(" %");
  4619. }
  4620. else {
  4621. if (data.DiscountType == 1)
  4622. $("#div_PlanVlm_" + len).find('#spn_DiscountType').text(" Val");
  4623. if (data.DiscountType == 3) {
  4624. $("#div_PlanVlm_" + len).find('#spn_DiscountType').text(" Fixed Val");
  4625. }
  4626. }
  4627. }
  4628. else {
  4629. $("#div_PlanVlm_" + len).find('.spn_off').addClass("hidden");
  4630. }
  4631. if (data.ItemVolumePayouts.length > 0) {
  4632. html = '<div class="" id="div_Foc_' + len + '"></div>';
  4633. $('#div_PlanVlm_' + len).after(html);
  4634. for (var i = 0; i < data.ItemVolumePayouts.length; i++) {
  4635. ItemOfferSelection.Instance().AddFoCItem(data.ItemVolumePayouts[i], len, Type, ItemId);
  4636. }
  4637. }
  4638. if (Type == "POS_Order") {
  4639. let CartItem_Index = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().g_CartItems_New.findIndex(x => x.ItemId == ItemId);
  4640. if (CartItem_Index != -1) {
  4641. let AppliedPlanVolumeId = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().g_CartItems_New[CartItem_Index].AppliedPlanVolumeId;
  4642. if (AppliedPlanVolumeId != 0) {
  4643. instance.HighlightAppliedPlans(AppliedPlanVolumeId, ItemId, false);
  4644. }
  4645. }
  4646. }
  4647. else if (Type == "Order") {
  4648. let IsCart = false;
  4649. if ($("#ulOrder_Cart").is(":visible")) {
  4650. IsCart = true;
  4651. }
  4652. if (!IsCart && !Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_FromContinueShopping) {
  4653. Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_AppliedOffers = Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_AppliedOffers.filter(x => x.ItemId != ItemId);
  4654. var sp_ItemIndex = instance.g_Selected_Plan.findIndex(x => x.ItemId == ItemId);
  4655. if (sp_ItemIndex != -1) {
  4656. let selectedPlan = instance.g_Selected_Plan[sp_ItemIndex];
  4657. Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_AppliedOffers.push({
  4658. ItemId: selectedPlan.ItemId,
  4659. OfferId: 0,
  4660. PlanId: 0,
  4661. PlanVolumeId: selectedPlan.PlanVolumeId,
  4662. IsSelected: true
  4663. });
  4664. }
  4665. }
  4666. let AppliedOffers = Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_AppliedOffers.filter(x => x.ItemId == ItemId);
  4667. for (var ao = 0; ao < AppliedOffers.length; ao++) {
  4668. let AppliedPlanVolumeId = AppliedOffers[ao].PlanVolumeId;
  4669. let IsSelected = AppliedOffers[ao].IsSelected;
  4670. instance.HighlightAppliedPlans(AppliedPlanVolumeId, ItemId, IsSelected);
  4671. }
  4672. }
  4673. else if (Type == "Estimate") {
  4674. let IsCart = false;
  4675. if ($("#ulOrder_Cart").is(":visible")) {
  4676. IsCart = true;
  4677. }
  4678. if (!IsCart && !Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_FromContinueShopping) {
  4679. Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_AppliedOffers = Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_AppliedOffers.filter(x => x.ItemId != ItemId);
  4680. var sp_ItemIndex = instance.g_Selected_Plan.findIndex(x => x.ItemId == ItemId);
  4681. if (sp_ItemIndex != -1) {
  4682. let selectedPlan = instance.g_Selected_Plan[sp_ItemIndex];
  4683. Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_AppliedOffers.push({
  4684. ItemId: selectedPlan.ItemId,
  4685. OfferId: 0,
  4686. PlanId: 0,
  4687. PlanVolumeId: selectedPlan.PlanVolumeId,
  4688. IsSelected: true
  4689. });
  4690. }
  4691. }
  4692. let AppliedOffers = Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_AppliedOffers.filter(x => x.ItemId == ItemId);
  4693. for (var ao = 0; ao < AppliedOffers.length; ao++) {
  4694. let AppliedPlanVolumeId = AppliedOffers[ao].PlanVolumeId;
  4695. let IsSelected = AppliedOffers[ao].IsSelected;
  4696. instance.HighlightAppliedPlans(AppliedPlanVolumeId, ItemId, IsSelected);
  4697. }
  4698. }
  4699. }
  4700. HighlightAppliedPlans(AppliedPlanVolumeId, ItemId, IsSelected) {
  4701. let instance = this;
  4702. if (IsSelected) {
  4703. $(".Card_Plan_Vlm_row_" + AppliedPlanVolumeId).css("background-color", "lavender");
  4704. var checkoffer = $(".Plan_Vlm_row_" + AppliedPlanVolumeId).find(".offers_applied").attr("id");
  4705. $("#" + checkoffer).find("u").text("Remove").removeClass('text-sucess').addClass('text-danger');
  4706. var sp_ItemIndex = instance.g_Selected_Plan.findIndex(x => x.ItemId == ItemId);
  4707. if (sp_ItemIndex != -1) {
  4708. let selectedPlan = instance.g_Selected_Plan[sp_ItemIndex];
  4709. instance.Bizgaze_Transact_Selected_Plan.push({
  4710. Volume: selectedPlan.Volume, value: selectedPlan.value, DiscountType: selectedPlan.DiscountType, PlanVolumeId: AppliedPlanVolumeId, ItemId: ItemId, focItemId: selectedPlan.focItemId
  4711. });
  4712. }
  4713. }
  4714. else {
  4715. $(".Card_Plan_Vlm_row_" + AppliedPlanVolumeId).css("background-color", "lightgoldenrodyellow");
  4716. $(".Card_Plan_Vlm_row_" + AppliedPlanVolumeId).find("u").text("Apply").addClass('text-sucess').removeClass('text-danger');
  4717. }
  4718. $("#frm_Bizgazetransact_ItemOfferSelection").find("#btn_Apply").removeAttr("style").removeClass("disabled");
  4719. }
  4720. UnHighlightPlan(AppliedPlanVolumeId, ItemId, Type) {
  4721. let instance = this;
  4722. $(".Card_Plan_Vlm_row_" + AppliedPlanVolumeId).find("u").text("Apply").addClass('text-sucess').removeClass('text-danger');
  4723. $(".Card_Plan_Vlm_row_" + AppliedPlanVolumeId).removeAttr("style");
  4724. var offerItemIndex = instance.Bizgaze_Transact_Selected_Plan.findIndex(x => x.ItemId == ItemId && x.PlanVolumeId == AppliedPlanVolumeId);
  4725. if (offerItemIndex != -1) {
  4726. instance.Bizgaze_Transact_Selected_Plan.splice(offerItemIndex, 1);
  4727. }
  4728. var sp_ItemIndex = instance.g_Selected_Plan.findIndex(x => x.ItemId == ItemId && x.PlanVolumeId == AppliedPlanVolumeId);
  4729. if (offerItemIndex != -1) {
  4730. instance.g_Selected_Plan.splice(sp_ItemIndex, 1);
  4731. }
  4732. if (Type == "Order") {
  4733. var appliedoffers_ItemIndex = Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_AppliedOffers.findIndex(x => x.ItemId == ItemId && x.PlanVolumeId == AppliedPlanVolumeId);
  4734. if (appliedoffers_ItemIndex != -1) {
  4735. Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_AppliedOffers.splice(appliedoffers_ItemIndex, 1);
  4736. }
  4737. }
  4738. if (Type == "Estimate") {
  4739. var appliedoffers_ItemIndex = Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_AppliedOffers.findIndex(x => x.ItemId == ItemId && x.PlanVolumeId == AppliedPlanVolumeId);
  4740. if (appliedoffers_ItemIndex != -1) {
  4741. Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_AppliedOffers.splice(appliedoffers_ItemIndex, 1);
  4742. }
  4743. }
  4744. }
  4745. AddFoCItem(FocItem, len, Type, RefItemId) {
  4746. var html = '<div class="mt-2 shadow px-2"><input type="hidden" id=' + FocItem.ItemId + ' class="selectedfocitem"><div class="d-flex align-items-center"><div class="check-btn mt-2"><input type="checkbox" id="IsApplyOffer_' + FocItem.ItemVolumePayoutId + '" class="mr-2 h-20p w-20p li_Pln_items_with_Checked"> <span class="checkmark"></span></div><div class="p-0"><span class="biz-highlight-text-color font-weight-600 mr-1">' + FocItem.Discount + '% </span> off on purchase of every <span class="list-item-main-title px-1">' + FocItem.Recur + ' </span> Quantity <br><span class="list-item-main-title px-1">' + FocItem.Quantity + ' </span> x <span class="list-item-main-title px-1 word-break">' + FocItem.ItemName + '</span><div></div>' +
  4747. '</div>';
  4748. $('#div_Foc_' + len).before(html);
  4749. var seen = '';
  4750. $('.plan_Name').each(function () {
  4751. var see = $(this).text();
  4752. if (seen.match(see)) {
  4753. $(this).remove();
  4754. }
  4755. else {
  4756. seen = seen + $(this).text();
  4757. }
  4758. });
  4759. if (Type == "Order") {
  4760. var ValidFocItemIndex = Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_ValidFocItems.findIndex(x => x.ItemId == FocItem.ItemId && x.RefItemIds == RefItemId);
  4761. if (!FocItem.IsFoC) {
  4762. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked", true);
  4763. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).attr("disabled", "true");
  4764. }
  4765. else if (FocItem.IsFoC && ValidFocItemIndex != -1) {
  4766. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked", true);
  4767. }
  4768. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).change(function () {
  4769. var Checked = $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked");
  4770. var FocItemIndex = Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_ValidFocItems.findIndex(x => x.ItemId == FocItem.ItemId && x.RefItemIds.toString().indexOf(RefItemId) != -1);
  4771. if (Checked) {
  4772. if (FocItemIndex == -1) {
  4773. Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_ValidFocItems.push({ ItemId: FocItem.ItemId, RefItemIds: RefItemId });
  4774. }
  4775. }
  4776. else {
  4777. if (FocItemIndex != -1) {
  4778. Bizgaze.Apps.Transact.Controls.OrderItems.Instance().g_ValidFocItems.splice(FocItemIndex, 1);
  4779. }
  4780. }
  4781. });
  4782. }
  4783. if (Type == "Estimate") {
  4784. var ValidFocItemIndex = Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_ValidFocItems.findIndex(x => x.ItemId == FocItem.ItemId && x.RefItemIds == RefItemId);
  4785. if (!FocItem.IsFoC) {
  4786. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked", true);
  4787. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).attr("disabled", "true");
  4788. }
  4789. else if (FocItem.IsFoC && ValidFocItemIndex != -1) {
  4790. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked", true);
  4791. }
  4792. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).change(function () {
  4793. var Checked = $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked");
  4794. var FocItemIndex = Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_ValidFocItems.findIndex(x => x.ItemId == FocItem.ItemId && x.RefItemIds.toString().indexOf(RefItemId) != -1);
  4795. if (Checked) {
  4796. if (FocItemIndex == -1) {
  4797. Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_ValidFocItems.push({ ItemId: FocItem.ItemId, RefItemIds: RefItemId });
  4798. }
  4799. }
  4800. else {
  4801. if (FocItemIndex != -1) {
  4802. Bizgaze.Apps.Transact.Controls.EstimateItems.Instance().g_ValidFocItems.splice(FocItemIndex, 1);
  4803. }
  4804. }
  4805. });
  4806. }
  4807. if (Type == "POS_Order") {
  4808. var ValidFocItemIndex = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().g_ValidFocItems.findIndex(x => x.ItemId == FocItem.ItemId && x.RefItemIds.indexOf(RefItemId) != -1);
  4809. if (!FocItem.IsFoC) {
  4810. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked", true);
  4811. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).attr("disabled", "true");
  4812. }
  4813. else if (FocItem.IsFoC && ValidFocItemIndex != -1) {
  4814. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked", true);
  4815. }
  4816. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).change(function () {
  4817. var Checked = $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked");
  4818. var FocItemIndex = Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().g_ValidFocItems.findIndex(x => x.ItemId == FocItem.ItemId && x.RefItemIds.indexOf(RefItemId) != -1);
  4819. if (Checked) {
  4820. if (FocItemIndex == -1) {
  4821. Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().g_ValidFocItems.push({ ItemId: FocItem.ItemId, RefItemIds: RefItemId });
  4822. }
  4823. }
  4824. else {
  4825. if (FocItemIndex != -1) {
  4826. Bizgaze.Apps.Transact.Controls.POSCartItems.Instance().g_ValidFocItems.splice(FocItemIndex, 1);
  4827. }
  4828. }
  4829. });
  4830. }
  4831. if (Type == "Pos") {
  4832. var ValidFocItemIndex = Bizgaze.Apps.Transact.Controls.Pos.Instance().offerItemsArray.findIndex(x => x.ItemId == FocItem.ItemId && x.RefItemId == RefItemId);
  4833. if (!FocItem.IsFoC) {
  4834. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked", true);
  4835. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).attr("disabled", "true").addClass("opacity-30");
  4836. }
  4837. else if (FocItem.IsFoC && ValidFocItemIndex != -1) {
  4838. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked", true);
  4839. }
  4840. $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).change(function () {
  4841. var Checked = $("#IsApplyOffer_" + FocItem.ItemVolumePayoutId).prop("checked");
  4842. var FocItemIndex = Bizgaze.Apps.Transact.Controls.Pos.Instance().offerItemsArray.findIndex(x => x.ItemId == FocItem.ItemId && x.RefItemId == RefItemId);
  4843. if (Checked) {
  4844. if (FocItemIndex == -1) {
  4845. Bizgaze.Apps.Transact.Controls.Pos.Instance().offerItemsArray.push({ ItemId: FocItem.ItemId, RefItemId: RefItemId });
  4846. }
  4847. }
  4848. });
  4849. }
  4850. }
  4851. Apply(element) {
  4852. let instance = this;
  4853. instance.navigationHelper.closePopUp();
  4854. ItemOfferSelection.Instance().ApplyOffer(instance.Bizgaze_Transact_Selected_Plan, element);
  4855. }
  4856. AddSpliItem(element) {
  4857. var array = {
  4858. orderItemId: 0,
  4859. invoiceItemId: 0,
  4860. itemId: element.find('.selectedItemId').val(),
  4861. packSize: 0,
  4862. packCount: 0,
  4863. packs: 0,
  4864. quantity: 0,
  4865. availPacks: 0,
  4866. availQty: 0,
  4867. Description: "",
  4868. isTaxInclusive: $("#hfIsTaxInclusive").val(),
  4869. addlDiscountPercent: 0,
  4870. addlDiscountValue: 0,
  4871. creditNote: 0,
  4872. priceListId: element.find('.hf_PriceList').val(),
  4873. invoiceallocations: null,
  4874. exciseInvoiceItem: null,
  4875. walletId: 0,
  4876. Adjustment: 0,
  4877. IsFoc: 0,
  4878. TariffNo: "",
  4879. exciseAmount: 0,
  4880. discountName: "",
  4881. discountId: 0,
  4882. description: "",
  4883. RefNo: "",
  4884. DiscountGroupId: 0,
  4885. DiscountGroupName: '',
  4886. RefInvoiceItemId: 0,
  4887. taxAdjustment: element.find('.hfItemTaxAdjsutmentVal').val(),
  4888. assesableAdjustment: element.find('.hfItemAssesableAdjustmentVal').val(),
  4889. inventoryTypeId: 0,
  4890. dcItemId: element.find('.dcItemId').val(),
  4891. ExchangeItem: element.find('.IsExchangeItem').val(),
  4892. unitPrice: element.find('.prodPrice').val(),
  4893. taxGroupId: element.find(".hfProdTax").val(),
  4894. BatchId: 0,
  4895. MrpId: 0,
  4896. SerialId: 0,
  4897. Name: '',
  4898. maxQty: 0,
  4899. accountId: element.find(".hf_Account").val(),
  4900. accountName: element.find(".txt_AccountName").val(),
  4901. taxGroupName: element.find(".txtProdTax").val(),
  4902. };
  4903. return array;
  4904. }
  4905. AddItemRowToSplitArray(Item, element, Quantity) {
  4906. var DcType = 2;
  4907. var BranchId = $(".txtAutoComplete_shiptoaddressid").val();
  4908. if ($('.hdn_invoicetypeid').val() == '1' || $('.hdn_invoicetypeid').val() == '4' || $('.hdn_invoicetypeid').val() == '5') {
  4909. BranchId = $(".txtAutoComplete_shipfromaddressid").val();
  4910. }
  4911. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "5") {
  4912. DcType = 1;
  4913. }
  4914. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemSetting(Item, BranchId, DcType).then(function (result) {
  4915. var EnableMrp = result.result.EnableMRP;
  4916. var EnableBatch = result.result.EnableBatchNo;
  4917. var Info = [];
  4918. if (EnableMrp == true) {
  4919. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getMrps(element.find(".selectedItemId").val(), DcType, BranchId).then(function (res) {
  4920. Info = res.result;
  4921. });
  4922. }
  4923. if (EnableBatch == true) {
  4924. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getBatches(element.find(".selectedItemId").val(), DcType, BranchId).then(function (res) {
  4925. Info = res.result;
  4926. });
  4927. }
  4928. if (Info.length > 0) {
  4929. var TotalQuantity = 0;
  4930. var TotalDisc = 0;
  4931. var TotalAmount = 0;
  4932. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "5") {
  4933. var itemQty = Quantity;
  4934. for (var x = 0; x < Info.length; x++) {
  4935. if (itemQty > 0) {
  4936. var itemrow = ItemOfferSelection.Instance().AddSpliItem(element);
  4937. let Qty = 0;
  4938. if (EnableMrp == true) {
  4939. itemrow.MrpId = Info[x].MrpId;
  4940. itemrow.Name = Info[x].Mrp + ' ( ' + Info[x].MrpQuantity + ' ) ';
  4941. Qty = Info[x].MrpQuantity;
  4942. }
  4943. else if (EnableBatch == true) {
  4944. itemrow.BatchId = Info[x].BatchId;
  4945. itemrow.Name = Info[0].BatchNo;
  4946. Qty = Info[0].BatchQuantity;
  4947. }
  4948. if (Qty > itemQty) {
  4949. itemrow.quantity = itemQty;
  4950. itemQty = itemQty - Info[x].Quantity;
  4951. }
  4952. else {
  4953. itemrow.quantity = Qty;
  4954. itemQty = itemQty - Qty;
  4955. }
  4956. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.push(itemrow);
  4957. TotalQuantity += Number(itemrow.quantity);
  4958. var discount = 0;
  4959. var qyt = Number(itemrow.quantity);
  4960. var price = Number(itemrow.unitPrice);
  4961. var excamt = Number(itemrow.exciseAmount);
  4962. var assesableAdjustment = Number(itemrow.assesableAdjustment);
  4963. var ItemAdjustment = Number(itemrow.Adjustment);
  4964. var discountAmount = Number(itemrow.addlDiscountValue);
  4965. var discountPercent = Number(itemrow.addlDiscountPercent);
  4966. discount = (((qyt * price) + assesableAdjustment + ItemAdjustment - excamt) * Number(discountPercent) / 100) + (Number(qyt) * Number(discountAmount));
  4967. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  4968. TotalDisc += discount;
  4969. var rowtotal = Number((qyt * price) + excamt + ItemAdjustment + assesableAdjustment);
  4970. var RowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowtotal - discount, 3);
  4971. TotalAmount += RowTotal;
  4972. }
  4973. }
  4974. }
  4975. else {
  4976. var itemrow = ItemOfferSelection.Instance().AddSpliItem(element);
  4977. if (EnableMrp == true) {
  4978. itemrow.MrpId = Info[0].MrpId;
  4979. itemrow.Name = Info[0].Mrp + ' ( ' + Info[0].Quantity + ' ) ';
  4980. }
  4981. else if (EnableBatch == true) {
  4982. itemrow.BatchId = Info[0].BatchId;
  4983. itemrow.Name = Info[0].BatchNo;
  4984. }
  4985. itemrow.quantity = Quantity;
  4986. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().SplitedInvoiceItemList.push(itemrow);
  4987. TotalQuantity += Number(itemrow.quantity);
  4988. var discount = 0;
  4989. var qyt = Number(itemrow.quantity);
  4990. var price = Number(itemrow.unitPrice);
  4991. var excamt = Number(itemrow.exciseAmount);
  4992. var assesableAdjustment = Number(itemrow.assesableAdjustment);
  4993. var ItemAdjustment = Number(itemrow.Adjustment);
  4994. var discountAmount = Number(itemrow.addlDiscountValue);
  4995. var discountPercent = Number(itemrow.addlDiscountPercent);
  4996. discount = (((qyt * price) + assesableAdjustment + ItemAdjustment - excamt) * Number(discountPercent) / 100) + (Number(qyt) * Number(discountAmount));
  4997. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  4998. TotalDisc += discount;
  4999. var rowtotal = Number((qyt * price) + excamt + ItemAdjustment + assesableAdjustment);
  5000. var RowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowtotal - discount, 3);
  5001. TotalAmount += RowTotal;
  5002. }
  5003. if (EnableMrp == true)
  5004. element.find('.spn_InvoiceItem').text("View MRP");
  5005. else
  5006. element.find('.spn_InvoiceItem').text("View Batch");
  5007. element.find('.prodQuantity').val();
  5008. element.find('.prodQuantity').val(TotalQuantity);
  5009. element.find('#inv_txtdiscount').val();
  5010. element.find('#inv_txtdiscount').val(TotalDisc);
  5011. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "6") {
  5012. element.find(".txtRowTotalwithAdjustment").val();
  5013. element.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(TotalAmount, 3));
  5014. }
  5015. else {
  5016. element.find('.prodTotalPrice').text('');
  5017. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(TotalAmount, 3));
  5018. }
  5019. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().GetPlanItems(element.find(".selectedItemId").val(), element.find('.prodQuantity').val(), element);
  5020. }
  5021. });
  5022. }
  5023. ApplyOffer(Item, element) {
  5024. if (element.hasClass('SplitItem')) {
  5025. var Qty = Number(element.find(".prodQuantity").val());
  5026. if (Qty == 0) {
  5027. ItemOfferSelection.Instance().AddItemRowToSplitArray(Item, element, Item[0].Volume);
  5028. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().update_total();
  5029. }
  5030. else if (Qty < Item[0].Volume) {
  5031. var ItemQty = Item[0].Volume - Qty;
  5032. ItemOfferSelection.Instance().AddItemRowToSplitArray(Item, element, ItemQty);
  5033. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().update_total();
  5034. }
  5035. else {
  5036. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().GetPlanItems(element.find(".selectedItemId").val(), Qty, element);
  5037. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().update_total();
  5038. }
  5039. }
  5040. else {
  5041. element.find(".prodQuantity").val(Item[0].Volume);
  5042. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().GetPlanItems(element.find(".selectedItemId").val(), element.find(".prodQuantity").val(), element);
  5043. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().update_total();
  5044. }
  5045. }
  5046. static Instance() {
  5047. if (this.instance === undefined) {
  5048. this.instance = new Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection();
  5049. }
  5050. return this.instance;
  5051. }
  5052. }
  5053. Invoices.ItemOfferSelection = ItemOfferSelection;
  5054. })(Invoices = Components.Invoices || (Components.Invoices = {}));
  5055. })(Components = Transact.Components || (Transact.Components = {}));
  5056. })(Transact = Apps.Transact || (Apps.Transact = {}));
  5057. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  5058. })(Bizgaze || (Bizgaze = {}));
  5059. var Bizgaze;
  5060. (function (Bizgaze) {
  5061. let Apps;
  5062. (function (Apps) {
  5063. let Transact;
  5064. (function (Transact) {
  5065. let Controls;
  5066. (function (Controls) {
  5067. class InvoiceItem extends Unibase.Platform.Core.BaseComponent {
  5068. constructor() {
  5069. super(...arguments);
  5070. this.rowIndex = 0;
  5071. this.itemIds = new Array();
  5072. this.dcItemIds = new Array();
  5073. this.SplitedInvoiceItemList = new Array();
  5074. this.deleted_invoiceItems = new Array();
  5075. this.invItemTaxAdjustmentList = new Array();
  5076. this.container = "";
  5077. this.AutoDc = false;
  5078. this.OrderSettingId = 0;
  5079. this.orderid = 0;
  5080. this.dcid = 0;
  5081. this.ClaimId = 0;
  5082. this.TurnOver = 0;
  5083. this.TaxRate = 0;
  5084. this.ContactTcsEnable = false;
  5085. this.EnableTenantTcs = false;
  5086. this.PanAvailable = false;
  5087. this.IswalkinCustomer = false;
  5088. this.ManageInvoice = 2;
  5089. this.ManageInvoiceTax = 2;
  5090. this.UOMs = [];
  5091. this.ChangedUOM = false;
  5092. this.isOfferChargeApplied = false;
  5093. }
  5094. init(formpropertyid, prop, callback) {
  5095. var instance = InvoiceItem.Instance();
  5096. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("platform/core/helpers/numberhelper/numberhelper.js", function () {
  5097. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  5098. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/paymentterms/paymenttermmanager.js", function () {
  5099. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/offers/offermanager.js", function () {
  5100. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/compact/components/details/details.js", function () {
  5101. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("platform/forms/components/formviewer/formviewer.js", function () {
  5102. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("libs/parsley/parsley.min.js", function () {
  5103. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  5104. instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
  5105. instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
  5106. });
  5107. });
  5108. });
  5109. });
  5110. });
  5111. });
  5112. });
  5113. });
  5114. }
  5115. loadControl(containerid, prop) {
  5116. let instance = this;
  5117. var html = '<div class="section_ItemDetails card"><div class="card-header d-flex flex-row align-item-center"><span class="my-auto">Item Details</span><div class="ml-auto w-60 d-flex flex-row-reverse align-items-center"><a href="javascript:void(0);" class="advanced-opitions mx-3"><i class="fa fa-sliders"></i></a><div class="hidden-element d-flex justify-content-end w-30 advchange_taxgroup"><input type="hidden" id="hdn_changetaxgroup" class="" value=""><select class="form-control change_taxgroup" value="" id="change_taxgroup" placeholder="Tax Group" data-label="Select Tax Group"style="width:100%;"></select></div></div><span class="ml-2"><a href="javascript:;" class="btn mr-20 btn-sm btn-primary btn-rounded text-white" id = "Item_Count">0</a></span></div><div class="card-body"><div class="row"><div id="control-container" class="control-group divCustomProperties divCustomProperties_InvoiceItemEntity controldata_0 col-sm-12 " data-size="12" data-propertyname="null" data-propertyid="0" data-doctypeid="0" data-level="0" data-doctypetable="null" data-doctypename="InvoiceItemEntity" data-isdefault="false" data-rowindex="13" data-formpropertyid="" data-controlname="InvoiceItems" data-validatename="InvoiceItems"><div class="panel panel-default" style="padding-bottom:10px" id="invoiceitem"><input type="hidden" id="hdn_customcontrol" class="value-control" value="Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().getobj();"><input type="hidden" id="hdninvoiceitem" class="" value="" data-isdynamic="true" data-propdoctypename=""><div class=""> <div id="tbl_InvoiceItems" class="col-sm-12 d-none d-lg-block pb-10"><div class="row lineheight wrapper-sm" style="border-bottom: 2px solid grey;"><div class="col-sm-4 min-padding"><strong class="ml-10">Item Name</strong></div><div class="col-sm-2 text-center"><strong class="">Qty</strong></div><div class="col-sm-2 text-center min-padding"><strong>Unit Price</strong></div><div class="col-sm-2 text-center min-padding"><strong>Disc.</strong></div><div class="col-sm-2 text-right min-padding"><strong>Total</strong></div></div></div></div><div class="panel-body InvoiceItems"><div class="item-row added-row InvoiceitemRow-0 "></div><div class="discount-row hidden"></div></div></div><div class="col-sm-12 row pr-0"><div class="col-sm-6"><a class="btn btn-outline-primary mt-2" title="Add Item" id="btnInvoiceItem"><span class="px-1"><i class="la la-plus"></i></span><span>Add Item</span></a><span> </span><a class="btn btn-outline-primary mt-2" title="Add Discount Item" id="btndiscountItem"> <span class="px-1"><i class="la la-plus"></i></span><span>Add Discount Item</span></a></div><div class="col-sm-6 pr-0"><div class="pull-right" style="padding-left:0px;padding-right:0px;"></div></div></div></div></div></div></div>';
  5118. $("#" + containerid).html(html);
  5119. $('.advanced-opitions').on('click', function () {
  5120. $('#change_taxgroup').val(null).trigger('change');
  5121. $('.advchange_taxgroup').toggleClass('hidden-element');
  5122. $('.advchange_taxgroup').find('.select2-selection__placeholder span').text('Select Tax Group');
  5123. });
  5124. InvoiceItem.instance.container = containerid;
  5125. InvoiceItem.Instance().loadChangeTaxGroupAutoComplete();
  5126. }
  5127. invoiceinit() {
  5128. if (InvoiceItem.Instance().orderid != 0) {
  5129. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  5130. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorderbranchsettings(InvoiceItem.Instance().orderid).then(function (response) {
  5131. if (response.result != null) {
  5132. if (response.result.SettingValue == "Invoice First") {
  5133. InvoiceItem.Instance().OrderSettingId = 2;
  5134. }
  5135. else if (response.result.SettingValue == "DC First" || response.result.SettingValue == "GRN First") {
  5136. InvoiceItem.Instance().OrderSettingId = 1;
  5137. }
  5138. }
  5139. });
  5140. }
  5141. $(".dropdown_istaxinclusive option[value='false']").attr('selected', 'true');
  5142. $(".dropdown_paymentmethodid option[value='0']").attr('selected', 'true');
  5143. $(".nettotal").remove();
  5144. var VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  5145. $("#" + VisibleContainerId).find(".btn_Save_Form").addClass("hidden");
  5146. var nettotal = '<strong class="nettotal mt-5 mr-5">0.00</strong>';
  5147. if ($('.Title').siblings('.btn-group').length > 0)
  5148. $('.Title').siblings('.btn-group').prepend(nettotal);
  5149. else
  5150. $('.Title').after('<strong class="nettotal mt-5 mr-5 ml-auto">0.00</strong>');
  5151. $('.txtAutoComplete_paymenttermid').change(function () {
  5152. InvoiceItem.Instance().LoadDueDays();
  5153. });
  5154. $('.date_journaldate').blur(function () {
  5155. InvoiceItem.Instance().LoadDueDays();
  5156. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") && $("#chk_tcsapplied").val() != undefined)
  5157. InvoiceItem.Instance().GetCustomerTurnOver();
  5158. });
  5159. $('.date_journaldate').change(function () {
  5160. var invdate = $('.date_journaldate').val().toString().split('/');
  5161. let todaydate = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(), "").split('/');
  5162. var Invoicedate = new Date(Number(invdate[2]), Number(invdate[1]) - 1, Number(invdate[0]));
  5163. var CurrentDate = new Date(Number(todaydate[2]), Number(todaydate[1]) - 1, Number(todaydate[0]));
  5164. if (Invoicedate > CurrentDate) {
  5165. bootbox.confirm("Are You Sure,You want to Continue with Future Invoice", function (result) {
  5166. if (result) {
  5167. InvoiceItem.Instance().GetAvailableWallets(Number($(".hdn_invoiceid").val()));
  5168. }
  5169. else {
  5170. var f = new Date();
  5171. $('.date_journaldate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(f, ""));
  5172. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(f, "");
  5173. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  5174. $('.hfdate_journaldate').val(tdate);
  5175. InvoiceItem.Instance().GetAvailableWallets(Number($(".hdn_invoiceid").val()));
  5176. }
  5177. });
  5178. }
  5179. else {
  5180. InvoiceItem.Instance().GetAvailableWallets(Number($(".hdn_invoiceid").val()));
  5181. }
  5182. InvoiceItem.Instance().GetDiscounts();
  5183. });
  5184. $('.date_refdate').blur(function () {
  5185. let refdate = $(".date_refdate").val();
  5186. if (refdate == "" || refdate == null) {
  5187. var f = new Date();
  5188. $('.date_refdate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(f, ""));
  5189. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(f, "");
  5190. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  5191. $('.hfdate_refdate').val(tdate);
  5192. $(".divCustomProperties_refdate").children().addClass("floating-label-form-group-with-value");
  5193. }
  5194. });
  5195. $(".section_Ebs").addClass("hidden");
  5196. $(".section_Details").addClass('hidden');
  5197. $(".section_ItemDetails").addClass('hidden');
  5198. $(".section_Ebs").addClass('hidden');
  5199. $(".section_InvoiceAmount").addClass('hidden');
  5200. $(".section_Description").addClass('hidden');
  5201. $(".section_BillingAndShippingDetails").addClass('hidden');
  5202. $(".section_AdvancedOptions").addClass("hidden");
  5203. $(".section_Description").addClass("hidden");
  5204. $(".section_Wallets").addClass("hidden");
  5205. $(".section_TCS").addClass("hidden");
  5206. $("#div_tcstaxrate").addClass("hidden");
  5207. $(".div_tcsadjustment").addClass("hidden");
  5208. $("#div_tcsamount").addClass("hidden");
  5209. $(".number_tcsamount").prop("disabled", true);
  5210. $(".number_tdsamount").prop("disabled", true);
  5211. $(".number_tdstaxrate").prop("disabled", true);
  5212. $('#chk_excludefromcampaign').prop('checked', false);
  5213. $(".txt_gstno").prop("disabled", true);
  5214. $(".section_InvoiceAmount .card-header").first().text('Amount');
  5215. $(".hrefSection_MoreOptions").click(function () {
  5216. if ($(".hrefSection_MoreOptions").text() == 'Less Options') {
  5217. $(".hrefSection_MoreOptions").text('More Options');
  5218. $(".section_AdvancedOptions").addClass("hidden");
  5219. }
  5220. else if ($(".hrefSection_MoreOptions").text() == 'More Options') {
  5221. $(".hrefSection_MoreOptions").text('Less Options');
  5222. $(".section_AdvancedOptions").removeClass("hidden");
  5223. }
  5224. });
  5225. if (Unibase.Platform.Membership.Infos.Identity.getCurrentUser().settings == null) {
  5226. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  5227. MessageHelper.Instance().showError("Please Configure Default Branch", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  5228. return false;
  5229. }
  5230. else if (Unibase.Platform.Membership.Infos.Identity.getSetting("companyid") == null || Unibase.Platform.Membership.Infos.Identity.getSetting("companyid") == undefined) {
  5231. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  5232. MessageHelper.Instance().showError("Please Configure Default Branch", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  5233. return false;
  5234. }
  5235. else {
  5236. var companyId = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("companyid"));
  5237. if ($(".hdn_invoicetypeid").val() != "6" && $(".hdn_invoicetypeid").val() != "7") {
  5238. var Parameters = [{ "ColumnName": "companyid", "Value": companyId }];
  5239. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_orgcontactid"), Parameters);
  5240. }
  5241. }
  5242. if ($(".hdn_invoiceid").val() == 0 && InvoiceItem.Instance().orderid == 0 && InvoiceItem.Instance().dcid == 0) {
  5243. $(".txtAutoComplete_orgcontactid").change(function () {
  5244. var orgid = Number($(".hfAutoCompleteId_orgcontactid").val());
  5245. if (orgid > 0) {
  5246. if ($(".section_Details").hasClass('hidden')) {
  5247. $(".section_Details").removeClass('hidden');
  5248. }
  5249. if ($(".section_ItemDetails").hasClass('hidden')) {
  5250. $(".section_ItemDetails").removeClass('hidden');
  5251. }
  5252. if ($(".section_InvoiceAmount").hasClass('hidden')) {
  5253. $(".section_InvoiceAmount").removeClass('hidden');
  5254. }
  5255. if ($(".section_Description").hasClass('hidden')) {
  5256. $(".section_Description").removeClass('hidden');
  5257. }
  5258. if ($(".section_BillingAndShippingDetails").hasClass('hidden')) {
  5259. $(".section_BillingAndShippingDetails").removeClass('hidden');
  5260. }
  5261. if ($(".section_Wallets").hasClass('hidden')) {
  5262. $(".section_Wallets").removeClass("hidden");
  5263. }
  5264. if ($(".section_TCS").hasClass('hidden')) {
  5265. $(".section_TCS").removeClass("hidden");
  5266. }
  5267. var organiztionid = $(".hfAutoCompleteId_orgcontactid").val();
  5268. if (organiztionid != 0 && organiztionid != undefined && organiztionid != -1) {
  5269. InvoiceItem.Instance().LoadContactDetails();
  5270. }
  5271. $("#btn_Save").removeClass('hidden');
  5272. var VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  5273. $("#" + VisibleContainerId).find(".btn_Save_Form").removeClass("hidden");
  5274. }
  5275. });
  5276. }
  5277. $('.dropdown_istaxinclusive').change(function () {
  5278. var invItems = InvoiceItem.Instance().getInvoiceItems();
  5279. InvoiceItem.Instance().update_total();
  5280. InvoiceItem.Instance().TotalAdjustment();
  5281. });
  5282. if (Unibase.Platform.Membership.Infos.Identity.getCurrentUser().isAdmin == true) {
  5283. InvoiceItem.Instance().ManageInvoice = 2;
  5284. InvoiceItem.Instance().ManageInvoiceTax = 2;
  5285. }
  5286. else {
  5287. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().GetInvoicePermissions(Number($(".hdn_invoicetypeid").val())).then(function (response) {
  5288. if (response.result.length > 0) {
  5289. for (var i = 0; i < response.result.length; i++) {
  5290. if (response.result[i].SettingName == Unibase.Platform.Apps.Enums.SettingType.Manage.toString()) {
  5291. InvoiceItem.Instance().ManageInvoice = response.result[i].SettingValue;
  5292. InvoiceItem.Instance().ManageInvoiceTax = response.result[i].SettingValue;
  5293. }
  5294. }
  5295. }
  5296. });
  5297. }
  5298. if ($(".WalletItems").hasClass('show')) {
  5299. $(".WalletItems").removeClass('show');
  5300. }
  5301. let invoiceid = $(".hdn_invoiceid").val();
  5302. if (invoiceid == "0") {
  5303. if (InvoiceItem.Instance().orderid != 0 || InvoiceItem.Instance().dcid != 0)
  5304. InvoiceItem.Instance().getDcDetails();
  5305. $('#txt_Adjustment').keypress(function (event) {
  5306. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8) || (event.which == 45)) {
  5307. }
  5308. else {
  5309. event.preventDefault();
  5310. }
  5311. }).on('paste', function (event) {
  5312. event.preventDefault();
  5313. });
  5314. }
  5315. else {
  5316. InvoiceItem.Instance().bindEditInvoiceDetails(invoiceid);
  5317. }
  5318. $('#change_taxgroup').change(function () {
  5319. if ($('#change_taxgroup option:selected').val() != undefined && $('#change_taxgroup option:selected').val() != 0) {
  5320. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  5321. InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupId = Number($('#change_taxgroup option:selected').val());
  5322. Controls.Invoices.SplitItem.Instance().update_TaxPercentage($('#change_taxgroup option:selected').val());
  5323. }
  5324. $(".InvoiceItems").find(".item-row").each(function () {
  5325. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  5326. var TaxGroupId = Number($('#change_taxgroup option:selected').val());
  5327. var txtTaxGroup = $(this).find(".prodTax");
  5328. var hfProdTax = $(this).find(".hfProdTax");
  5329. hfProdTax.val(TaxGroupId);
  5330. txtTaxGroup.empty();
  5331. txtTaxGroup.append(new Option($('#change_taxgroup option:selected').text(), TaxGroupId.toString(), true));
  5332. if (hfProdTax.val() != '')
  5333. InvoiceItem.Instance().update_tax($(this), hfProdTax.val());
  5334. }
  5335. });
  5336. }
  5337. });
  5338. }
  5339. addNetDiscountRow() {
  5340. InvoiceItem.Instance().adddiscountrow(null, "", "", true);
  5341. }
  5342. getDcDetails() {
  5343. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  5344. var VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  5345. $("#" + VisibleContainerId).find(".btn_Save_Form").removeClass("hidden");
  5346. $("#btn_Save").removeClass('hidden');
  5347. InvoiceItem.Instance().AutoDc = false;
  5348. let url = "";
  5349. if (InvoiceItem.Instance().dcid != 0) {
  5350. url = 'apis/v4/bizgaze/transact/dcs/getdc/dcid/' + InvoiceItem.Instance().dcid;
  5351. }
  5352. else {
  5353. url = "apis/v4/bizgaze/transact/orders/getorderbyorderid/id/" + InvoiceItem.Instance().orderid;
  5354. }
  5355. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getOrderDcDetails(url).then(function (response) {
  5356. if (response.result != null) {
  5357. if ($(".hdn_invoicetypeid").val() == "1")
  5358. $("#div_FormName").text("Create Sales Invoice");
  5359. else if ($(".hdn_invoicetypeid").val() == "2")
  5360. $("#div_FormName").text("Create Purchase Invoice");
  5361. if ($(".section_Details").hasClass('hidden')) {
  5362. $(".section_Details").removeClass('hidden');
  5363. }
  5364. if ($(".section_ItemDetails").hasClass('hidden')) {
  5365. $(".section_ItemDetails").removeClass('hidden');
  5366. }
  5367. if ($(".section_Ebs").hasClass('hidden')) {
  5368. $(".section_Ebs").removeClass('hidden');
  5369. }
  5370. if ($(".section_InvoiceAmount").hasClass('hidden')) {
  5371. $(".section_InvoiceAmount").removeClass('hidden');
  5372. }
  5373. if ($(".section_Description").hasClass('hidden')) {
  5374. $(".section_Description").removeClass('hidden');
  5375. }
  5376. if ($(".section_BillingAndShippingDetails ").hasClass('hidden')) {
  5377. $(".section_BillingAndShippingDetails ").removeClass('hidden');
  5378. }
  5379. if ($(".section_Wallets").hasClass('hidden')) {
  5380. $(".section_Wallets").removeClass("hidden");
  5381. }
  5382. if ($(".section_TCS").hasClass('hidden')) {
  5383. $(".section_TCS").removeClass("hidden");
  5384. }
  5385. let data = response.result;
  5386. $(".txtAutoComplete_orgcontactid").empty();
  5387. if (data.OrgContactId == 0) {
  5388. InvoiceItem.Instance().IswalkinCustomer = true;
  5389. $(".hfAutoCompleteId_orgcontactid").val(data.OrganizationId);
  5390. var selectedCompany = new Option(data.OrganizationName, data.OrganizationId, true);
  5391. $(".txtAutoComplete_orgcontactid").append(selectedCompany);
  5392. }
  5393. else {
  5394. InvoiceItem.Instance().IswalkinCustomer = false;
  5395. $(".hfAutoCompleteId_orgcontactid").val(data.OrgContactId);
  5396. var selectedCompany = new Option(data.OrganizationName + " - " + data.OrgContactName, data.OrgContactId, true);
  5397. $(".txtAutoComplete_orgcontactid").append(selectedCompany);
  5398. }
  5399. if (data.OrganizationId != 0) {
  5400. $(".hdn_organizationid").val(data.OrganizationId);
  5401. $("#hfInv_OrganizationName").val(data.OrganizationName);
  5402. }
  5403. else {
  5404. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorgcontact(data.OrgContactId).then(function (response) {
  5405. var data = response.result;
  5406. if (response.result != null && data.OrganizationId != 0) {
  5407. $(".hdn_organizationid").val(response.result.OrganizationId);
  5408. $("#hfInv_OrganizationName").val(data.OrganizationName);
  5409. }
  5410. });
  5411. }
  5412. $(".txt_gstno").val(response.result.GSTInNo);
  5413. $(".txtAutoComplete_billfromaddressid").append(new Option(data.BillFromAddressName, data.BillFromAddressId, true));
  5414. $(".txtAutoComplete_shipfromaddressid").append(new Option(data.ShipFromAddressName, data.ShipFromAddressId, true));
  5415. if (InvoiceItem.Instance().orderid != 0 && InvoiceItem.Instance().dcid == 0) {
  5416. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillingAddressName, data.BillingAddressId, true));
  5417. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShippingAddressName, data.ShippingAddressId, true));
  5418. }
  5419. else {
  5420. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillToAddressName, data.BillToAddressId, true));
  5421. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShipToAddressName, data.ShipToAddressId, true));
  5422. }
  5423. if ((InvoiceItem.Instance().orderid != 0 || InvoiceItem.Instance().dcid != 0) && InvoiceItem.Instance().AutoDc == false) {
  5424. $('.txtAutoComplete_billfromaddressid').prop('disabled', true);
  5425. $('.txtAutoComplete_shipfromaddressid').prop('disabled', true);
  5426. $('.txtAutoComplete_billtoaddressid').prop('disabled', true);
  5427. $('.txtAutoComplete_shiptoaddressid').prop('disabled', true);
  5428. }
  5429. $(".txtAutoComplete_orgcontactid").prop('disabled', true);
  5430. $('.hfAutoCompleteId_lobid').val(data.LobId);
  5431. $('.txtAutoComplete_lobid').empty();
  5432. $('.txtAutoComplete_lobid').append(new Option(data.LobName, data.LobId, true));
  5433. $('.txtAutoComplete_lobid').prop('disabled', true);
  5434. if (data.RefNo != "" && data.RefNo != null) {
  5435. $(".txt_refno").val(data.RefNo);
  5436. $(".div_refno").addClass("floating-label-form-group-with-value");
  5437. }
  5438. else {
  5439. $(".txt_refno").val("");
  5440. $(".div_refno").removeClass("floating-label-form-group-with-value");
  5441. }
  5442. $('.txtAutoComplete_salespersonid').append(new Option(data.SalesPersonName, data.SalesPersonId, true));
  5443. $('.hfAutoCompleteId_salespersonid').val(data.SalesPersonId);
  5444. if (InvoiceItem.Instance().orderid != 0 && InvoiceItem.Instance().orderid != undefined) {
  5445. if (data.PaymentTermId != 0) {
  5446. $('.hfAutoCompleteId_paymenttermid').val(data.PaymentTermId);
  5447. $('.txtAutoComplete_paymenttermid').append(new Option(data.PaymentTermName, data.PaymentTermId, true));
  5448. InvoiceItem.Instance().LoadDueDays();
  5449. $(".txtAutoComplete_paymenttermid").prop('disabled', true);
  5450. }
  5451. $(".dropdown_paymentmethodid").val(data.PaymentMethodId);
  5452. $(".dropdown_paymentmethodid").prop('disabled', true);
  5453. if (data.BranchId != 0)
  5454. $(".hdn_branchid").val(data.BranchId);
  5455. $(".dropdown_istaxinclusive").val(data.IsTaxInclusive.toString());
  5456. $(".dropdown_istaxinclusive").prop('disabled', true);
  5457. }
  5458. if (data.Description != null && data.Description != "")
  5459. $(".divCustomProperties_systemnotes").find("textarea").val(data.Description);
  5460. else
  5461. $(".divCustomProperties_systemnotes").find("textarea").val("");
  5462. $("#txt_AdjustmentAccountName").empty();
  5463. $("#hf_AdjustmentAccountId").val("0");
  5464. var Addr = $(".txtAutoComplete_billtoaddressid option:selected").val();
  5465. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  5466. Addr = $(".txtAutoComplete_billfromaddressid option:selected").val();
  5467. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid option:selected").val(), Addr);
  5468. InvoiceItem.Instance().bindAdjustmentAccount(data.LobId, Addr);
  5469. InvoiceItem.Instance().getGSTNo();
  5470. var Address = $(".txtAutoComplete_billtoaddressid option:selected").val();
  5471. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7")
  5472. Address = $(".txtAutoComplete_billfromaddressid option:selected").val();
  5473. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  5474. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressByContactId(Address).then(function (response) {
  5475. if (response.result != null) {
  5476. if (response.result.GSTNO != "" && response.result.GSTNO != null)
  5477. $(".txt_gstno").val(response.result.GSTNO);
  5478. }
  5479. });
  5480. });
  5481. if ((data.OrderId == 0 || data.OrderId == undefined) && (InvoiceItem.Instance().dcid != 0 && InvoiceItem.Instance().dcid != undefined)) {
  5482. InvoiceItem.Instance().bindDefaultPaymentTerm(data.OrganizationId, data.LobId);
  5483. }
  5484. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") && $("#chk_tcsapplied").val() != undefined) {
  5485. $("#div_tcstaxrate").addClass("hidden");
  5486. $(".div_tcsadjustment").addClass("hidden");
  5487. $("#div_tcsamount").addClass("hidden");
  5488. $(".number_tcsamount").prop("disabled", true);
  5489. InvoiceItem.Instance().GetCustomerTurnOver();
  5490. }
  5491. InvoiceItem.Instance().GetAvailableWallets(0);
  5492. InvoiceItem.Instance().loadOrderPendingItems();
  5493. InvoiceItem.Instance().IsCustomerIndustrial(data.LobId, data.OrganizationId);
  5494. }
  5495. });
  5496. });
  5497. }
  5498. bindSeries(lobid, branchid) {
  5499. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getSeries($("#hf_FormInstalledAppId").val(), branchid, lobid).then(function (response) {
  5500. if (response.result != null) {
  5501. var seriesData = [];
  5502. if (response.result.length > 0) {
  5503. $(".txtSeriesAutoComplete_seriesid").empty();
  5504. for (let s = 0; s < response.result.length; s++) {
  5505. let Series = response.result[s];
  5506. seriesData.push({ id: Series.SeriesId, text: Series.SeriesName, AddlData: Series.ManualNumbering });
  5507. }
  5508. $('.txtSeriesAutoComplete_seriesid').select2({
  5509. data: seriesData,
  5510. });
  5511. $(".txtSeriesAutoComplete_seriesid").val(response.result[0].SeriesId).trigger("change");
  5512. }
  5513. else {
  5514. Unibase.Platform.Series.Managers.SeriesManager.Instance().getActiveSeries(0, Number($("#hf_FormInstalledAppId").val())).then(function (response) {
  5515. var data = response.result;
  5516. if (data != null) {
  5517. if (data.length != 0) {
  5518. $(".txtSeriesAutoComplete_seriesid").empty();
  5519. for (var s = 0; s < data.length; s++) {
  5520. let Series = data[s];
  5521. seriesData.push({ id: Series.SeriesId, text: Series.SeriesName, AddlData: Series.ManualNumbering });
  5522. }
  5523. $('.txtSeriesAutoComplete_seriesid').select2({
  5524. data: seriesData,
  5525. });
  5526. $(".txtSeriesAutoComplete_seriesid").val(data[0].SeriesId).trigger("change");
  5527. }
  5528. }
  5529. });
  5530. }
  5531. }
  5532. else {
  5533. Unibase.Platform.Series.Managers.SeriesManager.Instance().getActiveSeries(0, Number($("#hf_FormInstalledAppId").val())).then(function (response) {
  5534. var data = response.result;
  5535. if (data != null) {
  5536. if (data.length != 0) {
  5537. $(".txtSeriesAutoComplete_seriesid").empty();
  5538. for (var s = 0; s < data.length; s++) {
  5539. var Series = new Option(data[s].SeriesName, data[s].SeriesId.toString(), true);
  5540. $(".txtSeriesAutoComplete_seriesid").append(Series);
  5541. $(".txtSeriesAutoComplete_seriesid").val(data[s].SeriesId);
  5542. }
  5543. $(".txtSeriesAutoComplete_seriesid").val(data[0].SeriesId);
  5544. }
  5545. }
  5546. });
  5547. }
  5548. });
  5549. }
  5550. bindAdjustmentAccount(lobid, branchid) {
  5551. $('#hf_AdjustmentAccountId').val("0");
  5552. $('#txt_AdjustmentAccountName').empty();
  5553. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/ledgers/ledgermanager.js", function () {
  5554. Bizgaze.Apps.Transact.Managers.LedgerManager.Instance().getLobLedgerSetting(lobid, branchid).then(function (response) {
  5555. if (response.result != null && response.result != "") {
  5556. $("#txt_AdjustmentAccountName").append(new Option(response.result.LedgerName, response.result.SettingValue1, true));
  5557. $("#hf_AdjustmentAccountId").val(response.result.SettingValue1);
  5558. $("#txt_AdjustmentAccountName").val(response.result.SettingValue1);
  5559. }
  5560. });
  5561. });
  5562. }
  5563. bindDefaultPaymentTerm(organizationid, lobid) {
  5564. $('.hfAutoCompleteId_paymenttermid').val(0);
  5565. $('.txtAutoComplete_paymenttermid').empty();
  5566. Bizgaze.Apps.Transact.Managers.PaymentTermManager.Instance().getPaymentTermByOrg(organizationid, lobid).then(function (response) {
  5567. var paymentterm = response.result;
  5568. if (paymentterm != null && paymentterm != "") {
  5569. $('.hfAutoCompleteId_paymenttermid').val(paymentterm.PaymentTermId);
  5570. $('.txtAutoComplete_paymenttermid').append(new Option(paymentterm.PaymentTermName, paymentterm.PaymentTermId, true));
  5571. if (paymentterm.DueDays != null && paymentterm.DueDays > 0) {
  5572. var from = $('.date_journaldate').val().toString().split("/");
  5573. var f = new Date(Number(from[2]), Number(from[1]) - 1, Number(from[0]));
  5574. var currentdate = f.setDate(f.getDate() + paymentterm.DueDays);
  5575. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(currentdate, ""));
  5576. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(currentdate), "");
  5577. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  5578. $('.hfdate_duedate').val(tdate);
  5579. }
  5580. }
  5581. });
  5582. }
  5583. LoadContactDetails() {
  5584. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorganization($(".hfAutoCompleteId_orgcontactid").val()).then(function (response) {
  5585. if (response.result != null && response.result != "") {
  5586. if (response.result.OrganizationTypeId == 1)
  5587. InvoiceItem.Instance().IswalkinCustomer = false;
  5588. else
  5589. InvoiceItem.Instance().IswalkinCustomer = true;
  5590. InvoiceItem.Instance().LoadSpocDetails($(".hfAutoCompleteId_orgcontactid").val());
  5591. }
  5592. else {
  5593. InvoiceItem.Instance().IswalkinCustomer = false;
  5594. InvoiceItem.Instance().LoadSpocDetails($(".hfAutoCompleteId_orgcontactid").val());
  5595. }
  5596. });
  5597. }
  5598. LoadSpocDetails(contactid) {
  5599. if ($('.hdn_invoicetypeid').val() == "1" || $('.hdn_invoicetypeid').val() == "6" || $('.hdn_invoicetypeid').val() == "4") {
  5600. $('.txtAutoComplete_billtoaddressid').empty();
  5601. $('.txtAutoComplete_shiptoaddressid').empty();
  5602. }
  5603. else {
  5604. $('.txtAutoComplete_billfromaddressid').empty();
  5605. $('.txtAutoComplete_shipfromaddressid').empty();
  5606. }
  5607. if ($(".hdn_invoiceid").val() == "0") {
  5608. $(".txtAutoComplete_LobId").empty();
  5609. $(".hfAutoCompleteId_LobId").empty();
  5610. }
  5611. $(".txtAutoComplete_salespersonid").empty();
  5612. $(".hfAutoCompleteId_salespersoid").empty();
  5613. if (InvoiceItem.Instance().IswalkinCustomer == true) {
  5614. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorganization(contactid).then(function (response) {
  5615. if (response.result != null) {
  5616. $(".hdn_organizationid").val(response.result.OrganizationId);
  5617. $("#hfInv_OrganizationName").val(response.result.OrganizationName);
  5618. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") && $("#chk_tcsapplied").val() != undefined) {
  5619. InvoiceItem.Instance().GetCustomerTurnOver();
  5620. }
  5621. $.when(InvoiceItem.Instance().loadAddressAutoCompletes(response.result.OrganizationId)).then(function () {
  5622. InvoiceItem.Instance().BindAddressDetails(response.result.OrganizationId);
  5623. InvoiceItem.Instance().GetAvailableWallets(0);
  5624. });
  5625. }
  5626. });
  5627. }
  5628. else {
  5629. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorgcontact(contactid).then(function (response) {
  5630. var data = response.result;
  5631. if (response.result != null && data.OrganizationId != 0) {
  5632. $(".hdn_organizationid").val(response.result.OrganizationId);
  5633. $("#hfInv_OrganizationName").val(data.OrganizationName);
  5634. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") && $("#chk_tcsapplied").val() != undefined) {
  5635. InvoiceItem.Instance().GetCustomerTurnOver();
  5636. }
  5637. $.when(InvoiceItem.Instance().loadAddressAutoCompletes(response.result.OrganizationId)).then(function () {
  5638. InvoiceItem.Instance().BindAddressDetails(response.result.OrganizationId);
  5639. InvoiceItem.Instance().GetAvailableWallets(0);
  5640. });
  5641. }
  5642. });
  5643. }
  5644. }
  5645. GetJournalAlloc(invoiceId) {
  5646. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getJournalAllocs(invoiceId).then(function (response) {
  5647. if (response.result.length > 0)
  5648. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  5649. });
  5650. }
  5651. formatDate(date) {
  5652. var datearray = date.split("/");
  5653. var newdate = datearray[1] + '/' + datearray[0] + '/' + datearray[2];
  5654. var d = new Date(newdate), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear();
  5655. if (month.length < 2)
  5656. month = '0' + month;
  5657. if (month.length < 2)
  5658. month = '0' + month;
  5659. if (day.length < 2)
  5660. day = '0' + day;
  5661. return [year, month, day].join('-');
  5662. }
  5663. GetAvailableWallets(invoiceid) {
  5664. var ContactId = $(".hdn_organizationid").val();
  5665. var invoiceId = 0;
  5666. if (invoiceid != 0 && $('#hfInv_IsRetun').val() != "1") {
  5667. invoiceId = Number($(".hdn_invoiceid").val());
  5668. }
  5669. if (invoiceId != 0)
  5670. InvoiceItem.Instance().GetJournalAlloc(invoiceId);
  5671. var invoicedate = $('.date_journaldate').val();
  5672. var invdate = InvoiceItem.Instance().formatDate(invoicedate);
  5673. var lobId = $(".txtAutoComplete_lobid").val();
  5674. if (lobId == null || lobId == undefined)
  5675. lobId = 0;
  5676. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getJournalWallets(invdate, invoiceId, ContactId, Number($(".hdn_invoicetypeid").val()), lobId).then(function (response) {
  5677. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/payments/wallet.component.js", function () {
  5678. if (response.result != null) {
  5679. Bizgaze.Apps.Transact.Controls.Wallet.Instance().loadInvoiceWallets(response.result);
  5680. }
  5681. });
  5682. });
  5683. }
  5684. BindAddressDetails(orgid) {
  5685. let branchid = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  5686. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getbranche(branchid).then(function (responce) {
  5687. if (responce.result != null) {
  5688. if (responce.result.DefaultWarehouseId != 0)
  5689. var ShipTo = new Option(responce.result.DefaultWarehouseName, responce.result.DefaultWarehouseId, true);
  5690. else
  5691. var ShipTo = new Option(responce.result.BranchName, responce.result.BranchId, true);
  5692. var BillTo = new Option(responce.result.BranchName, responce.result.BranchId, true);
  5693. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  5694. $(".txtAutoComplete_shiptoaddressid").append(ShipTo);
  5695. $(".txtAutoComplete_billtoaddressid").append(BillTo);
  5696. $(".txtAutoComplete_billtoaddressid").change(function () {
  5697. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid").val(), $(".txtAutoComplete_billtoaddressid").val());
  5698. InvoiceItem.Instance().bindAdjustmentAccount($(".txtAutoComplete_lobid").val(), responce.result.BranchId);
  5699. });
  5700. }
  5701. else {
  5702. $(".txtAutoComplete_shipfromaddressid").append(ShipTo);
  5703. $(".txtAutoComplete_billfromaddressid").append(BillTo);
  5704. $(".txtAutoComplete_billfromaddressid").change(function () {
  5705. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid").val(), $(".txtAutoComplete_billfromaddressid").val());
  5706. InvoiceItem.Instance().bindAdjustmentAccount($(".txtAutoComplete_lobid").val(), responce.result.BranchId);
  5707. });
  5708. }
  5709. }
  5710. });
  5711. this.fileCacheHelper.loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  5712. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressByContactId(orgid).then(function (response) {
  5713. if (response.result != null && response.result != "") {
  5714. var ShipTo = new Option(response.result.AddressName, response.result.ContactAddressId, true);
  5715. var BillTo = new Option(response.result.AddressName, response.result.ContactAddressId, true);
  5716. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4") {
  5717. $(".txtAutoComplete_shiptoaddressid").append(ShipTo);
  5718. $(".txtAutoComplete_billtoaddressid").append(BillTo);
  5719. $(".txtAutoComplete_billtoaddressid").change(function () {
  5720. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  5721. InvoiceItem.Instance().BindLoB();
  5722. });
  5723. });
  5724. InvoiceItem.Instance().getGSTNo();
  5725. }
  5726. else {
  5727. $(".txtAutoComplete_shipfromaddressid").append(ShipTo);
  5728. $(".txtAutoComplete_billfromaddressid").append(BillTo);
  5729. $(".txtAutoComplete_billfromaddressid").change(function () {
  5730. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  5731. InvoiceItem.Instance().BindLoB();
  5732. });
  5733. });
  5734. InvoiceItem.Instance().getGSTNo();
  5735. }
  5736. if (response.result.GSTNO != "" && response.result.GSTNO != null)
  5737. $(".txt_gstno").val(response.result.GSTNO);
  5738. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  5739. InvoiceItem.Instance().BindLoB();
  5740. });
  5741. }
  5742. else {
  5743. MessageHelper.Instance().showError("Please assign billing address and shipping address", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  5744. }
  5745. });
  5746. });
  5747. }
  5748. getGSTNo() {
  5749. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  5750. var gstno = $(".txt_gstno").val();
  5751. if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length > 0 && Number($(".hdn_invoiceid").val()) != 0) {
  5752. gstno = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_gstno").Value;
  5753. }
  5754. $(".txt_gstno").parent().addClass("floating-label-form-group-with-value");
  5755. if (gstno != null && gstno != "") {
  5756. $(".txt_gstno").val(gstno);
  5757. }
  5758. else
  5759. $(".txt_gstno").val("GSTIN not Assigned");
  5760. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4") {
  5761. $(".txtAutoComplete_billtoaddressid").change(function () {
  5762. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressById(Number($(".txtAutoComplete_billtoaddressid").val())).then(function (ress) {
  5763. if (ress.result != null) {
  5764. if (ress.result.GSTNO != "" && ress.result.GSTNO != null)
  5765. $(".txt_gstno").val(ress.result.GSTNO);
  5766. }
  5767. });
  5768. });
  5769. }
  5770. else {
  5771. $(".txtAutoComplete_billfromaddressid").change(function () {
  5772. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressById(Number($(".txtAutoComplete_billfromaddressid").val())).then(function (ress) {
  5773. if (ress.result != null) {
  5774. if (ress.result.GSTNO != "" && ress.result.GSTNO != null)
  5775. $(".txt_gstno").val(ress.result.GSTNO);
  5776. }
  5777. });
  5778. });
  5779. }
  5780. }
  5781. loadLobAndSp() {
  5782. var AddressId = $(".txtAutoComplete_billfromaddressid option:selected").val();
  5783. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4")
  5784. AddressId = $(".txtAutoComplete_billtoaddressid option:selected").val();
  5785. var lobParameters = [{ "ColumnName": "contactaddressid", "Value": AddressId, }];
  5786. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_lobid"), lobParameters);
  5787. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/orders/ordermanager.js", function () {
  5788. var SpParameters = [{ "ColumnName": "contactaddressid", "Value": AddressId, }];
  5789. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_salespersonid"), null);
  5790. });
  5791. }
  5792. BindLoB() {
  5793. $(".txtAutoComplete_lobid").empty();
  5794. $('#hf_AdjustmentAccountId').val("0");
  5795. $('#txt_AdjustmentAccountName').empty();
  5796. if ($(".hdn_invoiceid").val() == "0") {
  5797. $(".InvoiceItems").find(".item-addedrow").remove();
  5798. InvoiceItem.Instance().SplitedInvoiceItemList = new Array();
  5799. InvoiceItem.Instance().itemIds = [0];
  5800. InvoiceItem.Instance().dcItemIds = [0];
  5801. $("#txt_Adjustment").val("0");
  5802. $("#span_Adjustment").text("0");
  5803. InvoiceItem.Instance().update_total();
  5804. InvoiceItem.Instance().TotalAdjustment();
  5805. }
  5806. var AddressId = $(".txtAutoComplete_billfromaddressid option:selected").val();
  5807. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  5808. AddressId = $(".txtAutoComplete_billtoaddressid option:selected").val();
  5809. this.fileCacheHelper.loadJsFile("apps/crm/lobs/managers/lobmanager.js", function () {
  5810. if (AddressId == undefined) {
  5811. AddressId = 0;
  5812. }
  5813. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobsByAddressId(Number(AddressId)).then(function (response) {
  5814. if (response.message != '') {
  5815. Unibase.Platform.Forms.Components.FormViewer.Instance().showError(response.message);
  5816. }
  5817. if (response.result != "" && response.result != null) {
  5818. if (response.result.length == 1) {
  5819. var LoB = new Option(response.result[0].LobName, response.result[0].LobId, true);
  5820. $(".txtAutoComplete_lobid").append(LoB);
  5821. $(".txtAutoComplete_lobid").val(response.result[0].LobId);
  5822. InvoiceItem.Instance().BindSalesPerson(AddressId);
  5823. InvoiceItem.Instance().bindDefaultPaymentTerm($(".hdn_organizationid").val(), response.result[0].LobId);
  5824. var Addr = $(".txtAutoComplete_billtoaddressid option:selected").val();
  5825. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  5826. Addr = $(".txtAutoComplete_billfromaddressid option:selected").val();
  5827. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid option:selected").val(), Addr);
  5828. InvoiceItem.Instance().bindAdjustmentAccount(response.result[0].LobId, Addr);
  5829. }
  5830. }
  5831. });
  5832. });
  5833. $(".txtAutoComplete_lobid").change(function () {
  5834. InvoiceItem.Instance().bindDefaultPaymentTerm($(".hdn_organizationid").val(), $(".txtAutoComplete_lobid option:selected").val());
  5835. var Address = $(".txtAutoComplete_billtoaddressid option:selected").val();
  5836. var Billto = $(".txtAutoComplete_billfromaddressid option:selected").val();
  5837. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6") {
  5838. Address = $(".txtAutoComplete_billfromaddressid option:selected").val();
  5839. Billto = $(".txtAutoComplete_billtoaddressid option:selected").val();
  5840. }
  5841. InvoiceItem.Instance().BindSalesPerson(Billto);
  5842. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid option:selected").val(), Address);
  5843. InvoiceItem.Instance().bindAdjustmentAccount($(".txtAutoComplete_lobid option:selected").val(), Address);
  5844. $(".InvoiceItems").find(".item-addedrow").remove();
  5845. InvoiceItem.Instance().SplitedInvoiceItemList = new Array();
  5846. InvoiceItem.Instance().itemIds = [0];
  5847. InvoiceItem.Instance().dcItemIds = [0];
  5848. $("#txt_Adjustment").val("0");
  5849. InvoiceItem.Instance().update_total();
  5850. InvoiceItem.Instance().TotalAdjustment();
  5851. InvoiceItem.Instance().GetAvailableWallets(0);
  5852. });
  5853. }
  5854. BindSalesPerson(AddressId) {
  5855. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  5856. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getManagerDetails(Number($(".txtAutoComplete_lobid option:selected").val()), AddressId).then(function (response) {
  5857. if (response.result != null) {
  5858. var SalesPerson = new Option(response.result.ManagerName, response.result.EmployeeId, true);
  5859. $(".txtAutoComplete_salespersonid").empty();
  5860. $(".txtAutoComplete_salespersonid").append(SalesPerson);
  5861. $(".txtAutoComplete_salespersonid").val(response.result.EmployeeId);
  5862. }
  5863. else {
  5864. $(".txtAutoComplete_salespersonid").empty();
  5865. $(".txtAutoComplete_salespersonid").val(0);
  5866. $(".txtAutoComplete_salespersonid").text("");
  5867. }
  5868. });
  5869. });
  5870. }
  5871. LoadDueDays() {
  5872. if (InvoiceItem.Instance().dcid != 0 && InvoiceItem.Instance().AutoDc == false && InvoiceItem.Instance().OrderSettingId != 2) {
  5873. var invdate = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatServerDate($('.date_journaldate').val());
  5874. if (InvoiceItem.Instance().DcDate != undefined) {
  5875. var date = InvoiceItem.Instance().DcDate.toString();
  5876. var dcdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  5877. if (invdate < dcdate) {
  5878. var dctext = "DC";
  5879. if ($('.hdn_invoicetypeid').val() == "2")
  5880. dctext = "GRN";
  5881. MessageHelper.Instance().showError("Invoice Date should not be less than " + dctext + " Date", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  5882. }
  5883. }
  5884. }
  5885. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/paymentterms/paymenttermmanager.js", function () {
  5886. Bizgaze.Apps.Transact.Managers.PaymentTermManager.Instance().getPaymentTerm(Number($('.hfAutoCompleteId_paymenttermid').val())).then(function (result) {
  5887. if (result.result != null) {
  5888. if (result.result.DueDays > 0) {
  5889. if ($('.date_journaldate').val() == "") {
  5890. let todaydate = Unibase.Platform.Helpers.DateTimeHelper.Instance().currentDate();
  5891. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""));
  5892. $('.hfdate_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""));
  5893. }
  5894. else {
  5895. var from = $('.date_journaldate').val().toString().split('/');
  5896. var f = new Date(Number(from[2]), Number(from[1]) - 1, Number(from[0]));
  5897. var currentdate = f.setDate(f.getDate() + result.result.DueDays);
  5898. var currentdate1 = f.setDate(f.getDate() + result.result.DueDays + 1);
  5899. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(currentdate), ""));
  5900. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(currentdate), "");
  5901. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  5902. $('.hfdate_duedate').val(tdate);
  5903. }
  5904. }
  5905. }
  5906. });
  5907. });
  5908. }
  5909. loadAddressAutoCompletes(organizationid) {
  5910. var ToAddressParameters = [{ "ColumnName": "contactid", "Value": organizationid, }];
  5911. let invoicetypeid = $(".hdn_invoicetypeid").val();
  5912. if (invoicetypeid == "1" || invoicetypeid == "4" || invoicetypeid == "6") {
  5913. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billtoaddressid"), ToAddressParameters);
  5914. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shiptoaddressid"), ToAddressParameters);
  5915. $(".txtAutoComplete_billtoaddressid").change(function () {
  5916. if (Number($(".hdn_invoiceid").val()) == 0) {
  5917. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  5918. InvoiceItem.Instance().BindLoB();
  5919. });
  5920. }
  5921. });
  5922. }
  5923. else {
  5924. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billfromaddressid"), ToAddressParameters);
  5925. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shipfromaddressid"), ToAddressParameters);
  5926. $(".txtAutoComplete_billfromaddressid").change(function () {
  5927. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  5928. InvoiceItem.Instance().BindLoB();
  5929. });
  5930. });
  5931. }
  5932. var FromAddressParameters = [{ "ColumnName": "companyid", "Value": Number(Unibase.Platform.Membership.Infos.Identity.getSetting("companyid")) }];
  5933. if (invoicetypeid == "1" || invoicetypeid == "4" || invoicetypeid == "6") {
  5934. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billfromaddressid"), FromAddressParameters);
  5935. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shipfromaddressid"), FromAddressParameters);
  5936. }
  5937. else {
  5938. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billtoaddressid"), FromAddressParameters);
  5939. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shiptoaddressid"), FromAddressParameters);
  5940. }
  5941. }
  5942. loadControlSettings(controlsettingjson, formpropertyid) {
  5943. var instance = InvoiceItem.Instance();
  5944. $("#btnInvoiceItem").off().click(function () {
  5945. let lobid = $(".hfAutoCompleteId_lobid").val();
  5946. if (lobid == undefined || lobid == "" || lobid == "0") {
  5947. MessageHelper.Instance().showError("Please Select LoB", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  5948. return false;
  5949. }
  5950. else
  5951. InvoiceItem.instance.addRow();
  5952. });
  5953. $("#btndiscountItem").off().click(function () {
  5954. InvoiceItem.Instance().adddiscountrow(null, "", "", false);
  5955. });
  5956. instance.itemIds = new Array();
  5957. instance.dcItemIds = new Array();
  5958. instance.itemIds.push(0);
  5959. instance.dcItemIds.push(0);
  5960. instance.SplitedInvoiceItemList = new Array();
  5961. instance.deleted_invoiceItems = new Array();
  5962. instance.invItemTaxAdjustmentList = new Array();
  5963. instance.AutoDc = false;
  5964. instance.OrderSettingId = 0;
  5965. instance.orderid = 0;
  5966. instance.dcid = 0;
  5967. instance.IswalkinCustomer = false;
  5968. $('.inv_hdnfiels').empty();
  5969. var d = "<div class='inv_hdnfiels'></div>";
  5970. $(".section_CompanyDetails").prepend(d);
  5971. var hiddenfileds = "<input type='hidden' id='hfInv_OrganizationName' value=''/>" +
  5972. "<input type='hidden' id='hfInv_IsRetun' value='0'/>" +
  5973. "<input type='hidden' id='hfInv_wallet' value='false' />";
  5974. $('.inv_hdnfiels').append(hiddenfileds);
  5975. $(".hdn_branchid").val(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  5976. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  5977. for (let obj of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) {
  5978. if (obj.Key === "hf_" + InstalledAppId + "_orderid") {
  5979. InvoiceItem.Instance().orderid = Number(Number(obj.Value));
  5980. $(".hdn_orderid").val(Number(obj.Value));
  5981. if (Number(obj.Value) != 0) {
  5982. for (let ob of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) {
  5983. if (ob.Key === "hf_" + InstalledAppId + "_branchid")
  5984. $(".hdn_branchid").val(ob.Value);
  5985. }
  5986. }
  5987. }
  5988. if (obj.Key === "hf_" + InstalledAppId + "_dcid") {
  5989. InvoiceItem.instance.dcid = Number(obj.Value);
  5990. $(".hdn_dcid").val(Number(obj.Value));
  5991. }
  5992. if (obj.Key === "hf_" + InstalledAppId + "_claimid") {
  5993. InvoiceItem.instance.ClaimId = Number(obj.Value);
  5994. }
  5995. if (obj.Key === "hf_" + InstalledAppId + "_dcdate") {
  5996. InvoiceItem.instance.DcDate = obj.Value;
  5997. }
  5998. }
  5999. if ((InvoiceItem.instance.dcid == 0 || InvoiceItem.instance.dcid == undefined) && (InvoiceItem.instance.dcid == 0 || InvoiceItem.instance.dcid == undefined)) {
  6000. instance.AutoDc = true;
  6001. }
  6002. InvoiceItem.Instance().invoiceinit();
  6003. $("#txt_taxAajustment").blur(function () {
  6004. InvoiceItem.Instance().update_total();
  6005. InvoiceItem.Instance().TotalAdjustment();
  6006. });
  6007. $("#txt_assessableadjustment").blur(function () {
  6008. InvoiceItem.Instance().update_total();
  6009. InvoiceItem.Instance().TotalAdjustment();
  6010. });
  6011. $(document).ready(function (e) {
  6012. if (Number($("#hf_pk_value").val()) != 0 && $("#chk_tdsapplied").is(":checked")) {
  6013. $(".divCustomProperties_tdstaxcodeid").removeClass('hidden');
  6014. $(".divCustomProperties_tdstaxrate").removeClass('hidden');
  6015. $(".divCustomProperties_tdsamount").removeClass('hidden');
  6016. }
  6017. else {
  6018. $(".divCustomProperties_tdstaxcodeid").addClass('hidden');
  6019. $(".divCustomProperties_tdstaxrate").addClass('hidden');
  6020. $(".divCustomProperties_tdsamount").addClass('hidden');
  6021. }
  6022. $("#chk_tdsapplied").removeAttr("onclick");
  6023. $("#chk_tdsapplied").change(function () {
  6024. if ($(this).prop('checked') == false) {
  6025. $(".txtAutoComplete_tdstaxcodeid").val(0);
  6026. $(".txtAutoComplete_tdstaxcodeid").text("");
  6027. $(".number_tdstaxrate").val(0);
  6028. $(".divCustomProperties_tdstaxcodeid").addClass('hidden');
  6029. $(".divCustomProperties_tdstaxrate").addClass('hidden');
  6030. $(".divCustomProperties_tdsamount").addClass('hidden');
  6031. $("#chk_tcsapplied").removeAttr("disabled");
  6032. $("#hdnchk_tdsapplied").val("false");
  6033. }
  6034. else {
  6035. $("#div_tcstaxrate").addClass("hidden");
  6036. $(".div_tcsadjustment").addClass("hidden");
  6037. $("#div_tcsamount").addClass("hidden");
  6038. $('#chk_tcsapplied').prop('checked', false);
  6039. $('#chk_tcsapplied').attr('disabled', "true");
  6040. $(".divCustomProperties_tdstaxcodeid").removeClass('hidden');
  6041. $(".divCustomProperties_tdstaxrate").removeClass('hidden');
  6042. $(".divCustomProperties_tdsamount").removeClass('hidden');
  6043. $("#chk_tcsapplied").attr("disabled");
  6044. $("#hdnchk_tdsapplied").val("true");
  6045. }
  6046. InvoiceItem.Instance().update_total();
  6047. });
  6048. $(".txtAutoComplete_tdstaxcodeid").change(function () {
  6049. $(".number_tdstaxrate").val(Number($(".txtAutoComplete_tdstaxcodeid").attr('data-addldata')));
  6050. InvoiceItem.Instance().update_total();
  6051. });
  6052. });
  6053. }
  6054. loadPropertySettings(propertysettings, formpropertyid) {
  6055. }
  6056. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  6057. }
  6058. bindEditInvoiceDetails(invoiceid) {
  6059. var VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  6060. $("#" + VisibleContainerId).find(".btn_Save_Form").removeClass("hidden");
  6061. if ($('.hdn_invoicetypeid').val() == "1" && $("#hf_AppSettingName").val() == "Create Return") {
  6062. $('#hfInv_IsRetun').val(1);
  6063. $('.hdn_invoicetypeid').val("3");
  6064. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  6065. $("#div_FormName").text("Create Sales Return");
  6066. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  6067. $(".hdn_journalno").val(0);
  6068. }
  6069. else if ($('.hdn_invoicetypeid').val() == "2" && $("#hf_AppSettingName").val() == "Create Return") {
  6070. $('#hfInv_IsRetun').val(1);
  6071. $('.hdn_invoicetypeid').val("4");
  6072. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  6073. $("#div_FormName").text("Create Purchase Return");
  6074. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  6075. $(".hdn_journalno").val(0);
  6076. }
  6077. let invoicetypeid = $('.hdn_invoicetypeid').val();
  6078. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  6079. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceDetails(invoiceid).then(function (result) {
  6080. var data = result.result;
  6081. var companyId = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("companyid"));
  6082. var Parameters = [];
  6083. if ($(".hdn_invoicetypeid").val() != "6" && $(".hdn_invoicetypeid").val() != "7")
  6084. Parameters = [{ "ColumnName": "companyid", "Value": companyId }];
  6085. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_orgcontactid"), Parameters);
  6086. InvoiceItem.Instance().AutoDc = data.AutoDc;
  6087. if (data.OrgContactId == 0) {
  6088. InvoiceItem.Instance().IswalkinCustomer = true;
  6089. $(".hfAutoCompleteId_orgcontactid").val(data.OrganizationId);
  6090. var selectedCompany = new Option(data.OrganizationName, data.OrganizationId, true);
  6091. }
  6092. else {
  6093. InvoiceItem.Instance().IswalkinCustomer = false;
  6094. if (data.OrgContactName == null)
  6095. data.OrgContactName = "";
  6096. $(".hfAutoCompleteId_orgcontactid").val(data.OrgContactId);
  6097. var selectedCompany = new Option(data.OrganizationName + " - " + data.OrgContactName, data.OrgContactId, true);
  6098. }
  6099. $(".txtAutoComplete_orgcontactid").empty();
  6100. $(".txtAutoComplete_orgcontactid").append(selectedCompany);
  6101. if ($(".section_Details").hasClass('hidden')) {
  6102. $(".section_Details").removeClass('hidden');
  6103. }
  6104. if ($(".section_ItemDetails").hasClass('hidden')) {
  6105. $(".section_ItemDetails").removeClass('hidden');
  6106. }
  6107. if ($(".section_Ebs").hasClass('hidden')) {
  6108. $(".section_Ebs").removeClass('hidden');
  6109. }
  6110. if ($(".section_InvoiceAmount").hasClass('hidden')) {
  6111. $(".section_InvoiceAmount").removeClass('hidden');
  6112. }
  6113. if ($(".section_Description").hasClass('hidden')) {
  6114. $(".section_Description").removeClass('hidden');
  6115. }
  6116. if ($(".section_BillingAndShippingDetails").hasClass('hidden')) {
  6117. $(".section_BillingAndShippingDetails").removeClass('hidden');
  6118. }
  6119. if ($(".section_Wallets").hasClass('hidden')) {
  6120. $(".section_Wallets").removeClass("hidden");
  6121. }
  6122. if ($(".section_TCS").hasClass('hidden')) {
  6123. $(".section_TCS").removeClass("hidden");
  6124. }
  6125. $("#btn_Save").removeClass('hidden');
  6126. $(".txtAutoComplete_lobid").prop("disabled", true);
  6127. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  6128. if ($('#hfInv_IsRetun').val() == "1" && ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  6129. let todaydate = Unibase.Platform.Helpers.DateTimeHelper.Instance().currentDate();
  6130. $('.date_journaldate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""));
  6131. var tdate = moment(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""), "DD/MM/YYYY").format("YYYY/MM/DD");
  6132. $('.hfdate_journaldate').val(tdate);
  6133. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""));
  6134. $('.hfdate_duedate').val(tdate);
  6135. InvoiceItem.Instance().LoadDueDays();
  6136. }
  6137. else {
  6138. $('.date_journaldate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.InvoiceDate, ""));
  6139. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.InvoiceDate), "");
  6140. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  6141. $('.hfdate_journaldate').val(tdate);
  6142. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.DueDate, ""));
  6143. var date1 = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.DueDate), "");
  6144. tdate = moment(date1, "DD/MM/YYYY").format("YYYY/MM/DD");
  6145. $('.hfdate_duedate').val(tdate);
  6146. }
  6147. $('.date_refdate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.RefDate, ""));
  6148. date1 = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.RefDate), "");
  6149. tdate = moment(date1, "DD/MM/YYYY").format("YYYY/MM/DD");
  6150. $('.hfdate_refdate').val(tdate);
  6151. $.when(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().loadAddressAutoCompletes(data.OrganizationId)).then(function (response) {
  6152. $(".txtAutoComplete_billfromaddressid").empty();
  6153. $(".txtAutoComplete_billtoaddressid").empty();
  6154. $(".txtAutoComplete_shiptoaddressid").empty();
  6155. $(".txtAutoComplete_shipfromaddressid").empty();
  6156. if ($('.hdn_invoicetypeid').val() == "1" || $('.hdn_invoicetypeid').val() == "4" || $('.hdn_invoicetypeid').val() == "6") {
  6157. $(".hfAutoCompleteId_billfromaddressid").val(data.BillFromAddressId);
  6158. $(".txtAutoComplete_billfromaddressid").append(new Option(data.BillFromAddressName, data.BillFromAddressId, true));
  6159. $(".hfAutoCompleteId_billtoaddressid").val(data.BillToAddressId);
  6160. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillToAddressName, data.BillToAddressId, true));
  6161. $(".hfAutoCompleteId_shiptoaddressid").val(data.ShipToAddressId);
  6162. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShipToAddressName, data.ShipToAddressId, true));
  6163. $(".hfAutoCompleteId_shipfromaddressid").val(data.ShipFromAddressId);
  6164. $(".txtAutoComplete_shipfromaddressid").append(new Option(data.ShipFromAddressName, data.ShipFromAddressId, true));
  6165. }
  6166. else {
  6167. $(".hfAutoCompleteId_billfromaddressid").val(data.BillToAddressId);
  6168. $(".txtAutoComplete_billfromaddressid").append(new Option(data.BillToAddressName, data.BillToAddressId, true));
  6169. $(".hfAutoCompleteId_billtoaddressid").val(data.BillFromAddressId);
  6170. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillFromAddressName, data.BillFromAddressId, true));
  6171. $(".hfAutoCompleteId_shiptoaddressid").val(data.ShipFromAddressId);
  6172. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShipFromAddressName, data.ShipFromAddressId, true));
  6173. $(".hfAutoCompleteId_shipfromaddressid").val(data.ShipToAddressId);
  6174. $(".txtAutoComplete_shipfromaddressid").append(new Option(data.ShipToAddressName, data.ShipToAddressId, true));
  6175. }
  6176. InvoiceItem.Instance().loadLobAndSp();
  6177. InvoiceItem.Instance().getGSTNo();
  6178. $('.txtAutoComplete_lobid').empty();
  6179. $(".txtAutoComplete_lobid").append(new Option(data.LobName, data.LobId, true));
  6180. $(".hfAutoCompleteId_lobid").val(data.LobId);
  6181. $('.txtAutoComplete_salespersonid').empty();
  6182. $('.txtAutoComplete_salespersonid').append(new Option(data.SalesPersonName, data.SalesPersonId, true));
  6183. $('.hfAutoCompleteId_salespersonid').val(data.SalesPersonId);
  6184. $('hdn_OrganizationId').val(data.OrganizationId);
  6185. $("#hfInv_OrganizationName").val(data.OrganizationName);
  6186. $('.txtAutoComplete_paymenttermid').empty();
  6187. $('.hfAutoCompleteId_paymenttermid').val(data.PaymentTermId);
  6188. $('.txtAutoComplete_paymenttermid').append(new Option(data.PaymentTermName, data.PaymentTermId, true));
  6189. if (data.SeriesId != 0 && $('#hfInv_IsRetun').val() != "1") {
  6190. $(".txtSeriesAutoComplete_seriesid").empty();
  6191. $(".hfSeriesAutoCompleteId_seriesid").val(0);
  6192. $(".txtSeriesAutoComplete_seriesid").append(new Option(data.SeriesName, data.SeriesId, true));
  6193. $(".hfSeriesAutoCompleteId_seriesid").val(data.SeriesId);
  6194. }
  6195. else {
  6196. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  6197. if (data.SeriesId == 0 && data.InvoiceNo != null && data.InvoiceNo != "") {
  6198. $(".isManualSeries_seriesid").prop("checked", true);
  6199. $(".TextManualSeries").val(data.InvoiceNo);
  6200. }
  6201. else {
  6202. var Addr = $(".txtAutoComplete_billtoaddressid option:selected").val();
  6203. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  6204. Addr = $(".txtAutoComplete_billfromaddressid option:selected").val();
  6205. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid option:selected").val(), Addr);
  6206. }
  6207. }
  6208. if (($('#hfInv_IsRetun').val() != "1") && ($('.hdn_invoicetypeid').val() == "4" || $('.hdn_invoicetypeid').val() == "7" || $('.hdn_invoicetypeid').val() == "6" || $('.hdn_invoicetypeid').val() == "3")) {
  6209. $(".txtSeriesAutoComplete_seriesid").prop("disabled", true);
  6210. }
  6211. if (data.RefNo != "" && data.RefNo != null)
  6212. $(".txt_refno").val(data.RefNo);
  6213. $(".hdn_refinvoiceid").val(data.RefInvoiceId);
  6214. if ($('#hfInv_IsRetun').val() == "1" && ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4"))
  6215. $(".txt_refno").val(data.InvoiceNo);
  6216. if (data.AdjustmentAccountId != 0) {
  6217. $("#txt_AdjustmentAccountName").append(new Option(data.AdjustmentAccountName, data.AdjustmentAccountId, true));
  6218. $("#txt_AdjustmentAccountName").val(data.AdjustmentAccountId);
  6219. $("#hf_AdjustmentAccountId").val(data.AdjustmentAccountId);
  6220. }
  6221. if (data.AdjustmentAccountId == 0)
  6222. $('#txt_AdjustmentAccountName').empty();
  6223. if (data.AutoAdjustment == true) {
  6224. $('#chk_AutoAdjustment').prop('checked', true);
  6225. $('#txt_Adjustment').prop("disabled", true);
  6226. $(".span_AdjustmentAccountName").removeClass('hidden');
  6227. $("#txt_AdjustmentAccountName").addClass('required');
  6228. }
  6229. else {
  6230. $('#chk_AutoAdjustment').prop('checked', false);
  6231. $('#txt_Adjustment').prop("disabled", false);
  6232. $("#txt_AdjustmentAccountName").removeClass('required');
  6233. $(".span_AdjustmentAccountName").addClass('hidden');
  6234. }
  6235. $('#txt_Adjustment').val(data.Adjustment);
  6236. if (data.Adjustment != 0) {
  6237. $('.span_AdjustmentAccountName').removeClass('hidden');
  6238. $("#txt_AdjustmentAccountName").addClass('required');
  6239. }
  6240. else {
  6241. $('.span_AdjustmentAccountName').addClass('hidden');
  6242. $("#txt_AdjustmentAccountName").removeClass('required');
  6243. }
  6244. if (data.InvoiceStatusId == 6) {
  6245. $('#btnInvoiceItem').hide();
  6246. }
  6247. var Iswalkincustomer = false;
  6248. var contactid = data.OrgContactId;
  6249. if (data.OrgContactId == 0) {
  6250. Iswalkincustomer = true;
  6251. contactid = data.OrganizationId;
  6252. }
  6253. InvoiceItem.Instance().IsCustomerIndustrial(data.LobId, data.OrganizationId);
  6254. $(".chk_excludefromcampaign").prop("checked", data.ExcludeFromCampaign);
  6255. $("#hfId_istaxinclusive").val(data.IsTaxInclusive);
  6256. InvoiceItem.Instance().isOfferChargeApplied = data.IsOfferChargeApplied;
  6257. $(".dropdown_istaxinclusive").val(data.IsTaxInclusive.toString());
  6258. $(".dropdown_paymentmethodid").val(data.PaymentMethodId);
  6259. InvoiceItem.Instance().GetAvailableWallets(data.InvoiceId);
  6260. InvoiceItem.Instance().loadOrderPendingItems();
  6261. });
  6262. $(".txtAutoComplete_orgcontactid").change(function () {
  6263. InvoiceItem.Instance().LoadContactDetails();
  6264. });
  6265. if (data.GSTNO != "" && data.GSTNO != null)
  6266. $(".txt_gstno").val(data.GSTNO);
  6267. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getCustomerTurnOver($(".hdn_organizationid").val(), $(".hdn_invoiceid").val(), InvoiceItem.Instance().formatDate($(".date_journaldate").val()), $(".hdn_invoicetypeid").val()).then(function (res) {
  6268. if (res.result != null) {
  6269. InvoiceItem.Instance().TurnOver = res.result.TurnOver;
  6270. InvoiceItem.Instance().ContactTcsEnable = res.result.Enable;
  6271. InvoiceItem.Instance().EnableTenantTcs = res.result.EnableTenantTcs;
  6272. InvoiceItem.Instance().PanAvailable = res.result.PanAvailable;
  6273. InvoiceItem.Instance().TaxRate = res.result.TaxRate;
  6274. $(".hdn_tcstaxcodeaccountid").val(res.result.TCSTaxCodeAccountId);
  6275. $(".hdn_tcstaxcodeid").val(res.result.TCSTaxCodeId);
  6276. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
  6277. if (InvoiceItem.Instance().ContactTcsEnable == true && InvoiceItem.Instance().EnableTenantTcs == true && data.TcsApplied == true) {
  6278. $("#chk_tcsapplied").prop("checked", true);
  6279. $("#hdnchk_tcsapplied").val("true");
  6280. $("#div_tcstaxrate").removeClass("hidden");
  6281. $(".div_tcsadjustment").removeClass("hidden");
  6282. $("#div_tcsamount").removeClass("hidden");
  6283. $(".number_tcsamount").prop("disabled", true);
  6284. }
  6285. }
  6286. }
  6287. });
  6288. $("chk_tcsapplies").prop("checked", data.TcsApplied);
  6289. $(".hdn_tcstaxcodeid").val(data.TcsTaxCodeId);
  6290. $(".hdn_tcstaxcodeaccountid").val(data.TcsTaxCodeAccountId);
  6291. $(".number_tcstaxrate").val(data.TcsTaxRate);
  6292. $(".number_tcstaxrate").prop("disabled", true);
  6293. $(".txt_tcsadjustment").val(data.TcsAdjustment);
  6294. $(".number_tcsamount").val(data.TcsAmount);
  6295. $(".number_tcsamount").prop("disabled", true);
  6296. $(".number_tdsamount").prop("disabled", true);
  6297. $(".number_tdstaxrate").prop("disabled", true);
  6298. InvoiceItem.Instance().ContactTcsEnable = data.TcsApplied;
  6299. InvoiceItem.Instance().TaxRate = data.TcsTaxRate;
  6300. if (data.TcsApplied == true) {
  6301. $("#div_tcstaxrate").removeClass("hidden");
  6302. $(".div_tcsadjustment").removeClass("hidden");
  6303. $("#div_tcsamount").removeClass("hidden");
  6304. }
  6305. else {
  6306. $("#div_tcstaxrate").addClass("hidden");
  6307. $(".div_tcsadjustment").addClass("hidden");
  6308. $("#div_tcsamount").addClass("hidden");
  6309. }
  6310. $("#chk_tcsapplied").unbind();
  6311. $("#chk_tcsapplied").change(function () {
  6312. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  6313. $("#txt_Adjustment").val(0);
  6314. $(".hdn_adjustment").val(0);
  6315. }
  6316. if ($(this).prop('checked') == true) {
  6317. $(".divCustomProperties_tdstaxrate").addClass("hidden");
  6318. $(".divCustomProperties_tdsamount").addClass("hidden");
  6319. $(".divCustomProperties_tdstaxcodeid").addClass("hidden");
  6320. $(".chk_tdsapplied").attr("disabled");
  6321. $('#chk_tdsapplied').prop('checked', false);
  6322. }
  6323. else {
  6324. $(".chk_tdsapplied").removeAttr("disabled");
  6325. }
  6326. $(".div_tcsadjustment").addClass("floating-label-form-group-with-value");
  6327. if ($(this).prop('checked') == true && InvoiceItem.Instance().EnableTenantTcs == false && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  6328. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  6329. $("#hdnchk_tcsapplied").val("false");
  6330. $('#chk_tcsapplied').prop('checked', false);
  6331. }
  6332. else {
  6333. if ($(this).prop('checked') == true && $(".hdn_invoicetypeid").val() == "1") {
  6334. bootbox.confirm("Confirm if sale value is > 50,00,000 for this customer.In this current Financial Year.", function (result) {
  6335. if (result) {
  6336. $("#div_tcstaxrate").removeClass("hidden");
  6337. $(".div_tcsadjustment").removeClass("hidden");
  6338. $("#div_tcsamount").removeClass("hidden");
  6339. InvoiceItem.Instance().update_total();
  6340. InvoiceItem.Instance().TotalAdjustment();
  6341. }
  6342. else {
  6343. $("#div_tcstaxrate").addClass("hidden");
  6344. $(".div_tcsadjustment").addClass("hidden");
  6345. $("#div_tcsamount").addClass("hidden");
  6346. $('#chk_tcsapplied').prop('checked', false);
  6347. InvoiceItem.Instance().update_total();
  6348. InvoiceItem.Instance().TotalAdjustment();
  6349. }
  6350. });
  6351. }
  6352. else if ($(this).prop('checked') == true) {
  6353. $("#div_tcstaxrate").removeClass("hidden");
  6354. $(".div_tcsadjustment").removeClass("hidden");
  6355. $("#div_tcsamount").removeClass("hidden");
  6356. $("#chk_tdsapplied").removeAttr("disabled");
  6357. InvoiceItem.Instance().update_total();
  6358. InvoiceItem.Instance().TotalAdjustment();
  6359. }
  6360. else if ($(this).prop('checked') == false) {
  6361. $("#div_tcstaxrate").addClass("hidden");
  6362. $(".div_tcsadjustment").addClass("hidden");
  6363. $("#div_tcsamount").addClass("hidden");
  6364. $(".number_tcstaxrate").val(data.TcsTaxRate);
  6365. $(".number_tcstaxrate").prop("disabled", true);
  6366. $(".txt_tcsadjustment").val(data.TcsAdjustment);
  6367. $(".number_tcsamount").val(data.TcsAmount);
  6368. $(".number_tcsamount").prop("disabled", true);
  6369. InvoiceItem.Instance().update_total();
  6370. InvoiceItem.Instance().TotalAdjustment();
  6371. }
  6372. }
  6373. });
  6374. if ($("#chk_tdsapplied").prop('checked') == false) {
  6375. $(".divCustomProperties_tdstaxrate").addClass("hidden");
  6376. $(".divCustomProperties_tdsamount").addClass("hidden");
  6377. $(".divCustomProperties_tdstaxcodeid").addClass("hidden");
  6378. }
  6379. else
  6380. $("#chk_tcsapplied").attr("disabled");
  6381. $(".txt_tcsadjustment").unbind();
  6382. $(".txt_tcsadjustment").blur(function () {
  6383. InvoiceItem.Instance().update_total();
  6384. InvoiceItem.Instance().TotalAdjustment();
  6385. });
  6386. });
  6387. });
  6388. }
  6389. loadOrderPendingItems() {
  6390. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  6391. let instance = this;
  6392. let invoiceid = $(".hdn_invoiceid").val();
  6393. var orderid = $(".hdn_orderid").val();
  6394. var Dcid = $(".hdn_dcid").val();
  6395. var fromOrder = false;
  6396. var items = [];
  6397. var Invoiceitem = [];
  6398. $(".item-addedrow").remove();
  6399. var url = "";
  6400. if (Dcid != 0 && Dcid != undefined && orderid == 0) {
  6401. fromOrder = false;
  6402. url = "apis/v4/bizgaze/transact/Dc/getpendingdcitemsforinvoice/dcid/" + Dcid;
  6403. }
  6404. if (Dcid == 0 || Dcid == undefined || InvoiceItem.Instance().OrderSettingId == 2) {
  6405. if (orderid != "0" && orderid != undefined) {
  6406. fromOrder = true;
  6407. url = "apis/v4/bizgaze/transact/Orders/getpendingitemsforinvoice/orderid/" + orderid + "/ismergeorder/false";
  6408. }
  6409. }
  6410. else if (Dcid != 0 && Dcid != undefined) {
  6411. fromOrder = false;
  6412. url = "apis/v4/bizgaze/transact/Dc/getpendingdcitemsforinvoice/dcid/" + Dcid;
  6413. }
  6414. if (invoiceid != 0 && invoiceid != undefined && invoiceid != "null") {
  6415. fromOrder = false;
  6416. if ($('#hfInv_IsRetun').val() == "1") {
  6417. if ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")
  6418. url = "apis/v4/bizgaze/transact/invoices/getinvoiceitemsbyinvoiceid/invoiceid/" + invoiceid + "/isreturn/true/itemid/0";
  6419. }
  6420. else
  6421. url = "apis/v4/bizgaze/transact/invoices/getinvoiceitemsbyinvoiceid/invoiceid/" + invoiceid + "/isreturn/false/itemid/0";
  6422. }
  6423. if (url != "") {
  6424. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceItems(url).then(function (response) {
  6425. var oldTaxId = 0;
  6426. var totalQty = 0;
  6427. if (response.result != null && response.result.length > 0)
  6428. instance.ShowOrHideSaveBtn(false);
  6429. for (var i = 0; i < response.result.length; i++) {
  6430. var item = response.result[i];
  6431. var invoiceItemId = 0;
  6432. totalQty += item.Quantity;
  6433. if (invoiceid != "0" && invoiceid != undefined && invoiceid != "null") {
  6434. invoiceItemId = item.InvoiceItemId;
  6435. item.IsOfferChargeApplied = InvoiceItem.Instance().isOfferChargeApplied;
  6436. }
  6437. InvoiceItem.Instance().isOfferChargeApplied = true;
  6438. $(".hdn_isofferchargeapplied").val('true');
  6439. var refInvoiceItemId = 0;
  6440. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $("#hf_AppSettingName").val() == "Create Return")
  6441. refInvoiceItemId = item.InvoiceItemId;
  6442. if (i == 0)
  6443. oldTaxId = item.TaxGroupId;
  6444. if (oldTaxId != item.TaxGroupId && i != 0)
  6445. $('#addDiscount').addClass('hidden');
  6446. var maxQty = 0;
  6447. if (item.OrderItemPendingQty > 0)
  6448. maxQty = item.OrderItemPendingQty;
  6449. var pendingQuantity = item.OrderItemPendingQty > 0 ? item.OrderItemPendingQty : 0;
  6450. if (invoiceItemId != 0)
  6451. maxQty = item.Quantity + pendingQuantity;
  6452. if (item.DcItemId == undefined)
  6453. item.DcItemId = 0;
  6454. if (item.TaxAdjustment == undefined)
  6455. item.TaxAdjustment = 0;
  6456. if (item.AssesableAdjustment == undefined)
  6457. item.AssesableAdjustment = 0;
  6458. if (item.IsFoc == undefined)
  6459. item.IsFoc = false;
  6460. if (item.OfferItemId == undefined)
  6461. item.OfferItemId = 0;
  6462. if (item.DiscountPercent == undefined)
  6463. item.DiscountPercent = 0;
  6464. if (item.DiscountValue == undefined)
  6465. item.DiscountValue = 0;
  6466. if (item.IsSpecialPrice == undefined)
  6467. item.IsSpecialPrice = false;
  6468. if (item.MrpId == 0)
  6469. item.EnableMRP = false;
  6470. var itemRow = {
  6471. orderItemId: item.OrderItemId,
  6472. invoiceItemId: invoiceItemId,
  6473. itemName: item.ItemName,
  6474. itemId: item.ItemId,
  6475. itemSKU: item.ItemSKU,
  6476. unitName: item.UnitName,
  6477. packSize: item.PackSize,
  6478. packCount: item.PackCount,
  6479. packs: item.Packs,
  6480. quantity: item.Quantity,
  6481. availPacks: item.AvailablePacks,
  6482. availQty: item.AvailableQty,
  6483. listPrice: 0,
  6484. description: item.Description,
  6485. taxGroupName: item.TaxGroupName,
  6486. taxGroupId: item.TaxGroupId,
  6487. isTaxInclusive: $("#hfId_istaxinclusive").val(),
  6488. addlDiscountPercent: item.DiscountPercent,
  6489. addlDiscountValue: item.DiscountAmount,
  6490. creditNote: 0,
  6491. priceListId: 0,
  6492. batchId: 0,
  6493. unitPrice: item.UnitPrice,
  6494. invoiceallocations: null,
  6495. exciseInvoiceItem: null,
  6496. accountId: item.LedgerId,
  6497. accountName: item.LedgerName,
  6498. walletId: 0,
  6499. Adjustment: 0,
  6500. IsFoc: item.IsFoc,
  6501. TariffNo: "",
  6502. exciseAmount: item.ExciseAmount,
  6503. discountName: "",
  6504. discountId: 0,
  6505. refNo: item.RefNo,
  6506. DiscountGroupId: item.DiscountGroupId,
  6507. DiscountGroupName: item.DiscountGroupName,
  6508. ExchangeItem: item.ExchangeDC,
  6509. maxQty: maxQty,
  6510. RefInvoiceItemId: refInvoiceItemId,
  6511. MrpId: item.MrpId,
  6512. taxAdjustment: item.TaxAdjustment,
  6513. assesableAdjustment: item.AssesableAdjustment,
  6514. inventoryTypeId: item.InventoryTypeId,
  6515. IsBoMItem: item.IsBoMItem,
  6516. dcItemId: item.DcItemId,
  6517. TotalRowAmount: 0,
  6518. TotalDiscount: 0,
  6519. BatchId: item.BatchId,
  6520. OfferItemId: item.OfferItemId,
  6521. AlternateUnitId: item.AlternateUnitId,
  6522. DefaultSize: item.DefaultSize,
  6523. ParentBOMItemId: item.ParentBOMItemId,
  6524. IsSpecialPrice: item.IsSpecialPrice,
  6525. IsMultipleUOMs: item.IsMultipleUOMs,
  6526. MultipleUoms: item.MultipleUOMs,
  6527. IsManualUOM: item.IsManualUOM,
  6528. ConversionQuantity: item.ConversionQuantity,
  6529. AlternateUnitName: item.AlternateUnitName,
  6530. };
  6531. var EnableMrp = item.EnableMRP;
  6532. var EnableBatch = item.EnableBatch;
  6533. if (item.IsFoc == true)
  6534. Invoiceitem.push(itemRow);
  6535. else if (item.DcItemId != 0 && EnableMrp != true && EnableBatch != true)
  6536. Invoiceitem.push(itemRow);
  6537. else if (item.InvoiceItemId == 0) {
  6538. if (InvoiceItem.Instance().orderid != 0 && Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_ordertypeid").Value) == 2 && EnableMrp != true && EnableBatch != true)
  6539. Invoiceitem.push(itemRow);
  6540. }
  6541. else if (item.InvoiceItemId == 0) {
  6542. if (InvoiceItem.Instance().orderid != 0 && Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_ordertypeid").Value) == 1 && ((EnableMrp != true && EnableBatch != true) || Number(item.AvailableQty) <= 0))
  6543. Invoiceitem.push(itemRow);
  6544. }
  6545. else if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && ((EnableMrp != true && EnableBatch != true)))
  6546. Invoiceitem.push(itemRow);
  6547. else if (($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3") && EnableMrp != true && EnableBatch != true)
  6548. Invoiceitem.push(itemRow);
  6549. else if ($(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7")
  6550. Invoiceitem.push(itemRow);
  6551. else {
  6552. if (item.InventoryTypeId != 5 && item.InventoryTypeId != 6 && item.InventoryTypeId != 7) {
  6553. var total = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  6554. var nonexcise = total - itemRow.exciseAmount;
  6555. var disc = ((nonexcise * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  6556. var Rowtotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(total - disc, 3);
  6557. InvoiceItem.Instance().SplitedInvoiceItemList.push({
  6558. orderItemId: item.OrderItemId,
  6559. invoiceItemId: invoiceItemId,
  6560. itemName: item.ItemName,
  6561. itemId: item.ItemId,
  6562. itemSKU: item.ItemSKU,
  6563. unitName: item.UnitName,
  6564. packSize: item.PackSize,
  6565. packCount: item.PackCount,
  6566. packs: item.Packs,
  6567. quantity: item.Quantity,
  6568. availPacks: item.AvailablePacks,
  6569. availQty: item.AvailableQty,
  6570. listPrice: 0,
  6571. description: item.Description,
  6572. taxGroupName: item.TaxGroupName,
  6573. taxGroupId: item.TaxGroupId,
  6574. isTaxInclusive: $("#hfId_istaxinclusive").val(),
  6575. addlDiscountPercent: item.DiscountPercent,
  6576. addlDiscountValue: item.DiscountAmount,
  6577. creditNote: 0,
  6578. priceListId: 0,
  6579. batchId: 0,
  6580. unitPrice: item.UnitPrice,
  6581. invoiceallocations: null,
  6582. exciseInvoiceItem: null,
  6583. accountId: item.LedgerId,
  6584. accountName: item.LedgerName,
  6585. walletId: 0,
  6586. Adjustment: 0,
  6587. IsFoc: 0,
  6588. TariffNo: "",
  6589. exciseAmount: item.ExciseAmount,
  6590. discountName: "",
  6591. discountId: 0,
  6592. refNo: item.RefNo,
  6593. DiscountGroupId: item.DiscountGroupId,
  6594. DiscountGroupName: item.DiscountGroupName,
  6595. ExchangeItem: item.ExchangeDC,
  6596. maxQty: maxQty,
  6597. RefInvoiceItemId: refInvoiceItemId,
  6598. MrpId: item.MrpId,
  6599. taxAdjustment: item.TaxAdjustment,
  6600. assesableAdjustment: item.AssesableAdjustment,
  6601. inventoryTypeId: item.InventoryTypeId,
  6602. IsBoMItem: item.IsBoMItem,
  6603. dcItemId: item.DcItemId,
  6604. TotalRowAmount: Rowtotal,
  6605. TotalDiscount: disc,
  6606. BatchId: item.BatchId,
  6607. TotalAmount: Rowtotal,
  6608. ParentBOMItemId: item.ParentBOMItemId
  6609. });
  6610. if (items.length != 0 && items.find(x => x.itemId == item.ItemId) != undefined) {
  6611. var multipleExist = items.find(x => x.itemId == item.ItemId);
  6612. multipleExist.quantity += itemRow.quantity;
  6613. var RowTotal = 0;
  6614. var rowtotal = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  6615. var nonexiceamount = rowtotal - itemRow.exciseAmount;
  6616. var discount = ((nonexiceamount * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  6617. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  6618. RowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowtotal - discount, 3);
  6619. multipleExist.TotalRowAmount = Number(multipleExist.TotalRowAmount) + Number(RowTotal);
  6620. multipleExist.TotalDiscount = Number(multipleExist.TotalDiscount) + Number(discount);
  6621. if (InvoiceItem.Instance().OrderSettingId == 1) {
  6622. var Qty = Number(maxQty);
  6623. multipleExist.maxQty = Qty + Number(multipleExist.maxQty);
  6624. }
  6625. else {
  6626. var Qty = Number(item.Quantity);
  6627. multipleExist.maxQty = Qty + Number(multipleExist.maxQty);
  6628. }
  6629. }
  6630. else {
  6631. var RowTotal = 0;
  6632. var rowtotal = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  6633. var nonexiceamount = rowtotal - itemRow.exciseAmount;
  6634. var discount = ((nonexiceamount * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  6635. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  6636. RowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowtotal - discount, 3);
  6637. itemRow.TotalRowAmount = Number(itemRow.TotalRowAmount) + Number(RowTotal);
  6638. itemRow.TotalDiscount = Number(discount);
  6639. items.push(itemRow);
  6640. }
  6641. }
  6642. else {
  6643. Invoiceitem.push(itemRow);
  6644. }
  6645. }
  6646. $.each(item.InvItemTaxAdjustments, function (e) {
  6647. var data = $(this);
  6648. var rowData = data[0];
  6649. InvoiceItem.Instance().invItemTaxAdjustmentList.push(rowData);
  6650. });
  6651. }
  6652. for (let j1 = 0; j1 < items.length; j1++) {
  6653. let j = items[j1];
  6654. var emptyRow = {
  6655. orderItemId: j.orderItemId,
  6656. invoiceItemId: 0,
  6657. itemName: j.itemName,
  6658. itemId: j.itemId,
  6659. itemSKU: j.itemSKU,
  6660. unitName: "",
  6661. packSize: 0,
  6662. packCount: 0,
  6663. packs: 0,
  6664. quantity: j.quantity,
  6665. availPacks: 0,
  6666. availQty: j.availQty,
  6667. listPrice: 0,
  6668. description: "",
  6669. taxGroupName: j.taxGroupName,
  6670. taxGroupId: j.taxGroupId,
  6671. isTaxInclusive: $("#hf_istaxinclusive").val(),
  6672. addlDiscountPercent: 0,
  6673. addlDiscountValue: j.addlDiscountValue,
  6674. creditNote: 0,
  6675. priceListId: 0,
  6676. batchId: 0,
  6677. unitPrice: j.unitPrice,
  6678. invoiceallocations: null,
  6679. exciseInvoiceItem: null,
  6680. accountId: j.accountId,
  6681. accountName: j.accountName,
  6682. walletId: 0,
  6683. Adjustment: 0,
  6684. IsFoc: j.IsFoc,
  6685. TariffNo: "",
  6686. exciseAmount: 0,
  6687. discountName: "",
  6688. discountId: 0,
  6689. refNo: "",
  6690. DiscountGroupId: 0,
  6691. DiscountGroupName: '',
  6692. RefInvoiceItemId: 0,
  6693. MrpId: j.MrpId,
  6694. taxAdjustment: 0,
  6695. assesableAdjustment: 0,
  6696. inventoryTypeId: 0,
  6697. dcItemId: 0,
  6698. TotalRowAmount: j.TotalRowAmount,
  6699. BatchId: j.BatchId,
  6700. maxQty: j.maxQty,
  6701. TotalDiscount: j.TotalDiscount,
  6702. ParentBOMItemId: j.ParentBOMItemId,
  6703. IsSpecialPrice: j.IsSpecialPrice
  6704. };
  6705. if (j.dcItemId != 0)
  6706. InvoiceItem.Instance().dcItemIds.push(j.dcItemId);
  6707. InvoiceItem.Instance().addDataRow(emptyRow, true);
  6708. if (items.length - 1 == j1) {
  6709. if (invoiceid != 0)
  6710. instance.GetDiscounts();
  6711. instance.ShowOrHideSaveBtn(true);
  6712. }
  6713. }
  6714. for (let k1 = 0; k1 < Invoiceitem.length; k1++) {
  6715. let k = Invoiceitem[k1];
  6716. if (k.dcItemId != 0)
  6717. InvoiceItem.Instance().dcItemIds.push(k.dcItemId);
  6718. InvoiceItem.Instance().addDataRow(k, false);
  6719. if (Invoiceitem.length - 1 == k1) {
  6720. if (invoiceid != 0)
  6721. instance.GetDiscounts();
  6722. instance.ShowOrHideSaveBtn(true);
  6723. }
  6724. }
  6725. $("#totalinvoiceqty").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalQty, 2));
  6726. });
  6727. }
  6728. }
  6729. getwalletinvoiceditems() {
  6730. var JournalAlloc = new Array();
  6731. $("#tbl_WalletItems").find(".walletitem-addedrow").each(function () {
  6732. JournalAlloc.push({
  6733. journalAllocId: $(this).find(".journalAllocId").val(),
  6734. RefAllocId: $(this).find(".refAllocId").val(),
  6735. JournalId: $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_Invoiceid").val(),
  6736. AdjustedAmount: Number($(this).find(".hfAdjustedAmount").val()),
  6737. TotalAmount: Number($(this).find(".totalAmount").text()),
  6738. IsWallet: true,
  6739. CurrentAmount: Number($(this).find(".currentAmount").val()),
  6740. });
  6741. });
  6742. return JournalAlloc;
  6743. }
  6744. ShowOrHideSaveBtn(IsShow) {
  6745. let instance = this;
  6746. if (!IsShow) {
  6747. instance.navigationHelper.showLoading();
  6748. $("#btnDynamicSave").prop("disabled", true);
  6749. }
  6750. else {
  6751. instance.navigationHelper.hideLoading();
  6752. $("#btnDynamicSave").prop("disabled", false);
  6753. }
  6754. }
  6755. getInvoiceItems() {
  6756. var invItemList = new Array();
  6757. $(".InvoiceItems").find(".item-row").each(function () {
  6758. if (!$(this).hasClass('SplitItem')) {
  6759. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  6760. let ParentBOMItemId = $(this).find(".hf_ParentBOMItemId").val();
  6761. if (ParentBOMItemId == null)
  6762. ParentBOMItemId = 0;
  6763. var invoicetermid = $(this).find(".invoiceTermId").val();
  6764. var invoiceitemid = Number($(this).find(".selectedInvoiceItemId").val());
  6765. var refInvoiceitemid = Number($(this).find(".refInvoiceItemId").val());
  6766. var orderItemId = Number($(this).find(".orderItemId").val());
  6767. var ItemId = Number($(this).find(".selectedItemId").val());
  6768. var packs = 0;
  6769. var prodprice = Number($(this).find(".prodPrice").val());
  6770. var quantity = Number($(this).find(".prodQuantity").val());
  6771. var prodpricelist = 0;
  6772. var description = $(this).find(".prodDesc").val();
  6773. var MrpId = Number($(this).find(".hfMrpId").val());
  6774. var discountAmount = 0;
  6775. var discountPercent = 0;
  6776. var rowTotal = Number($(this).find(".prodTotalPrice").text());
  6777. if (($(".hdn_invoicetypeid").val() == "2") && invoiceitemid != 0) {
  6778. rowTotal = Number($(this).find(".hfRowTotalwithAdjustment").val());
  6779. }
  6780. var Quantity = Number($(this).find(".prodQuantity").val());
  6781. var ConversionQuantity = Quantity;
  6782. let SelectedUnitId = 0;
  6783. let DefaultSize = 0;
  6784. let AlternateSize = 0;
  6785. if ($(this).find(".hf_IsMultipleUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
  6786. let ItemId = Number($(this).find(".selectedItemId").val());
  6787. SelectedUnitId = Number($(this).find(".ddl_MultipleUOMs").val());
  6788. if (SelectedUnitId != 0 && SelectedUnitId != 1) {
  6789. var Uom = InvoiceItem.Instance().UOMs.find(x => x.ItemId == ItemId);
  6790. var SelectedUOM = Uom.MultipleUOMs.find(x => x.SchemaDetailId == SelectedUnitId);
  6791. DefaultSize = SelectedUOM.DefaultSize;
  6792. AlternateSize = SelectedUOM.AlternateSize;
  6793. ConversionQuantity = Number(Quantity) * (AlternateSize / DefaultSize);
  6794. }
  6795. }
  6796. else if ($(this).find(".hf_IsManualUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
  6797. SelectedUnitId = Number($(this).find(".hf_AlternateUnitId").val());
  6798. ConversionQuantity = Number($(this).find(".hf_ConversionQuantity").val());
  6799. }
  6800. if (($(this).find(".btnInvoice_DiscType option:selected").text().trim() == 'Val' || $(this).find(".btnInvoice_DiscType option:selected").text().trim() == 'Mul') && $(this).find('.inv_txtaddldiscount').val() != '' && $(this).find('.inv_txtaddldiscount').val() != undefined) {
  6801. discountAmount = Number($(this).find('.inv_txtaddldiscount').val());
  6802. }
  6803. else if ($(this).find(".btnInvoice_DiscType option:selected").text().trim() == '%' && $(this).find('.inv_txtaddldiscount').val() != '' && $(this).find('.inv_txtaddldiscount').val() != undefined) {
  6804. discountPercent = Number($(this).find('.inv_txtaddldiscount').val());
  6805. }
  6806. var TaxGroupId = Number($(this).find(".hfProdTax").val());
  6807. let accountid = Number($(this).find(".txt_Account").val());
  6808. let foc = ($(this).find(".hf_IsFoc").val() == 'true');
  6809. invItemList.push({
  6810. InvoiceItemId: invoiceitemid,
  6811. OrderItemId: orderItemId,
  6812. ItemId: ItemId,
  6813. Packs: packs,
  6814. TaxGroupId: TaxGroupId,
  6815. Description: description,
  6816. PriceListId: prodpricelist,
  6817. UnitPrice: prodprice,
  6818. DiscountAmount: discountAmount,
  6819. DiscountPercent: discountPercent,
  6820. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  6821. AccountId: accountid,
  6822. Adjustment: Number($(this).find(".hfRowTotalAdjustment").val()),
  6823. TotalAmount: Number(rowTotal),
  6824. Quantity: Number(Quantity),
  6825. ExciseAmount: 0,
  6826. RefNo: $(this).find(".refNo").val(),
  6827. DiscountGroupId: Number($(this).find("#hfProdDiscountGroupId").val()),
  6828. RefInvoiceItemId: Number(refInvoiceitemid),
  6829. MrpId: Number(MrpId),
  6830. DcItemId: Number($(this).find(".dcItemId").val()),
  6831. BatchId: 0,
  6832. IsFoc: foc,
  6833. OfferItemId: ($(this).find(".hfOfferedItemId").val() == null || $(this).find(".hfOfferedItemId").val() == undefined) ? 0 : Number($(this).find(".hfOfferedItemId").val()),
  6834. AlternateUnitId: SelectedUnitId,
  6835. DefaultSize: DefaultSize,
  6836. ParentBOMItemId: Number(ParentBOMItemId),
  6837. ConversionQuantity: Number(ConversionQuantity)
  6838. });
  6839. }
  6840. }
  6841. });
  6842. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  6843. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_IsRetun').val() == "1") {
  6844. InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId = 0;
  6845. }
  6846. invItemList.push({
  6847. InvoiceItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId),
  6848. OrderItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].orderItemId),
  6849. ItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId),
  6850. TaxGroupId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupId),
  6851. Description: InvoiceItem.Instance().SplitedInvoiceItemList[i].description,
  6852. PriceListId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].priceListId),
  6853. UnitPrice: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice),
  6854. DiscountAmount: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountValue),
  6855. DiscountPercent: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountPercent),
  6856. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  6857. AccountId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].accountId),
  6858. Adjustment: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].Adjustment),
  6859. TotalAmount: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].TotalAmount),
  6860. Quantity: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity),
  6861. ExciseAmount: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount),
  6862. RefNo: InvoiceItem.Instance().SplitedInvoiceItemList[i].refNo,
  6863. DiscountGroupId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].DiscountGroupId),
  6864. RefInvoiceItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].RefInvoiceItemId),
  6865. MrpId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].MrpId) == -1 ? 0 : Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].MrpId),
  6866. DcItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId),
  6867. BatchId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].BatchId),
  6868. IsFoc: false,
  6869. OfferItemId: 0,
  6870. });
  6871. }
  6872. $(".InvoiceItems").find(".discount-row").each(function () {
  6873. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  6874. var rowname = "discount-row";
  6875. var appliedOnWhole = false;
  6876. var totalElement = $(this).find(".netdiscount-row-total");
  6877. if (totalElement.length != 0) {
  6878. appliedOnWhole = true;
  6879. rowname = "netdiscount-row";
  6880. }
  6881. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  6882. var ItemId = $(this).find(".hfSelectedChargeId").val();
  6883. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  6884. var ledgerId = $(this).find(".hdnChargeLedgerId").val();
  6885. var percent = $(this).find(".percentage").val();
  6886. var value = $(this).find(".fixedvalue").val();
  6887. var desc = $(this).find(".discountDesc").val();
  6888. var totalamount = $(this).find("." + rowname + "-total").html();
  6889. invItemList.push({
  6890. InvoiceItemId: $(this).find(".selectedInvoiceItemId").val() == undefined ? 0 : Number($(this).find(".selectedInvoiceItemId").val()),
  6891. OrderItemId: 0,
  6892. ItemId: Number(ItemId),
  6893. Packs: 0,
  6894. TaxGroupId: Number($(this).find(".hfProdTax").val()),
  6895. Description: $(this).find(".discountDesc").val(),
  6896. PriceListId: 0,
  6897. UnitPrice: 0,
  6898. DiscountAmount: Number($(this).find(".fixedvalue").val()),
  6899. DiscountPercent: Number($(this).find(".percentage").val()),
  6900. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  6901. AccountId: Number($(this).find(".hf_Account").val()),
  6902. RowDiscount: Number(totalamount),
  6903. SendToWallet: 0,
  6904. Adjustment: 0,
  6905. TotalAmount: 0,
  6906. Quantity: 1,
  6907. ExciseAmount: 0,
  6908. RefNo: "",
  6909. DiscountGroupId: 0,
  6910. RefInvoiceItemId: 0,
  6911. MrpId: 0,
  6912. BatchId: 0,
  6913. DcItemId: Number($(this).find(".dcItemId").val()),
  6914. IsFoc: false,
  6915. OfferItemId: 0,
  6916. });
  6917. }
  6918. });
  6919. $(".netdiscount-row").each(function () {
  6920. var rowname = "";
  6921. var appliedOnWhole = false;
  6922. var totalElement = $(this).find(".netdiscount-row-total");
  6923. if (totalElement.length != 0) {
  6924. appliedOnWhole = true;
  6925. rowname = "netdiscount-row";
  6926. }
  6927. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  6928. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  6929. var ItemId = $(this).find(".hfSelectedChargeId").val();
  6930. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  6931. var ledgerId = $(this).find(".hdnChargeLedgerId").val();
  6932. var percent = $(this).find(".percentage").val();
  6933. var value = $(this).find(".fixedvalue").val();
  6934. var desc = $(this).find(".discountDesc").val();
  6935. var totalamount = $(this).find("." + rowname + "-total").html();
  6936. invItemList.push({
  6937. InvoiceItemId: $(this).find(".selectedInvoiceItemId").val() == undefined ? 0 : Number($(this).find(".selectedInvoiceItemId").val()),
  6938. OrderItemId: 0,
  6939. ItemId: Number(ItemId),
  6940. Packs: 0,
  6941. TaxGroupId: Number($(this).find(".hfProdTax").val()),
  6942. Description: $(this).find(".discountDesc").val(),
  6943. PriceListId: 0,
  6944. UnitPrice: 0,
  6945. DiscountAmount: Number($(this).find(".fixedvalue").val()),
  6946. DiscountPercent: Number($(this).find(".percentage").val()),
  6947. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  6948. AccountId: Number($(this).find(".hf_Account").val()),
  6949. RowDiscount: Number(totalamount),
  6950. SendToWallet: 0,
  6951. Adjustment: 0,
  6952. TotalAmount: 0,
  6953. Quantity: 1,
  6954. ExciseAmount: 0,
  6955. RefNo: "",
  6956. DiscountGroupId: 0,
  6957. RefInvoiceItemId: 0,
  6958. MrpId: 0,
  6959. BatchId: 0,
  6960. DcItemId: Number($(this).find(".dcItemId").val()),
  6961. IsFoc: false,
  6962. OfferItemId: 0,
  6963. });
  6964. }
  6965. });
  6966. $(".expense-row").each(function () {
  6967. var rowname = "";
  6968. var appliedOnWhole = false;
  6969. var totalElement = $(this).find(".expense-row-total");
  6970. if (totalElement.length != 0) {
  6971. appliedOnWhole = true;
  6972. rowname = "expense-row";
  6973. }
  6974. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  6975. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  6976. var ItemId = $(this).find(".hfSelectedChargeId").val();
  6977. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  6978. var ledgerId = $(this).find(".hdnChargeLedgerId").val();
  6979. var percent = $(this).find(".percentage").val();
  6980. var value = $(this).find(".fixedvalue").val();
  6981. var desc = $(this).find(".discountDesc").val();
  6982. var totalamount = $(this).find("." + rowname + "-total").html();
  6983. if (Number($(this).find(".expfixedvalue").val()) != 0 || Number($(this).find(".exppercentage").val()) != 0) {
  6984. invItemList.push({
  6985. InvoiceItemId: $(this).find(".selectedInvoiceItemId").val() == undefined ? 0 : Number($(this).find(".selectedInvoiceItemId").val()),
  6986. OrderItemId: 0,
  6987. ItemId: Number(ItemId),
  6988. Packs: 0,
  6989. TaxGroupId: Number($(this).find(".hfProdTax").val()),
  6990. Description: $(this).find(".expenseDesc").val(),
  6991. PriceListId: 0,
  6992. UnitPrice: 0,
  6993. DiscountAmount: -Number($(this).find(".expfixedvalue").val()),
  6994. DiscountPercent: -Number($(this).find(".exppercentage").val()),
  6995. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  6996. AccountId: Number($(this).find(".hf_Account").val()),
  6997. RowDiscount: -Number(totalamount),
  6998. SendToWallet: 0,
  6999. Adjustment: 0,
  7000. TotalAmount: 0,
  7001. Quantity: 1,
  7002. ExciseAmount: 0,
  7003. RefNo: "",
  7004. DiscountGroupId: 0,
  7005. RefInvoiceItemId: 0,
  7006. MrpId: 0,
  7007. BatchId: 0,
  7008. DcItemId: Number($(this).find(".dcItemId").val()),
  7009. IsFoc: false,
  7010. OfferItemId: 0,
  7011. });
  7012. }
  7013. }
  7014. });
  7015. return invItemList;
  7016. }
  7017. getCharges() {
  7018. var ChargeList = new Array();
  7019. var chargeIndex = 0;
  7020. InvoiceItem.Instance().update_discount_total();
  7021. InvoiceItem.Instance().update_expense_total();
  7022. $(".discount-row,.netdiscount-row").each(function () {
  7023. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  7024. var rowname = "discount-row";
  7025. var appliedOnWhole = false;
  7026. var totalElement = $(this).find(".netdiscount-row-total");
  7027. if (totalElement.length != 0) {
  7028. appliedOnWhole = true;
  7029. rowname = "netdiscount-row";
  7030. }
  7031. if ($(this).find(".hfSelectedChargeId").val() != "" && $(this).find(".hfSelectedChargeId").val() != "0") {
  7032. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  7033. chargeIndex += 1;
  7034. var ChargeId = $(this).find(".hfSelectedChargeId").val();
  7035. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  7036. var ledgerId = $(this).find(".hf_Account").val();
  7037. var percent = $(this).find(".percentage").val();
  7038. var value = $(this).find(".fixedvalue").val();
  7039. var desc = $(this).find(".discountDesc").val();
  7040. var totalamount = $(this).find("." + rowname + "-total").html();
  7041. ChargeList.push({
  7042. InvoiceChargeId: Number(invoicechargeid),
  7043. ChargeId: Number(ChargeId),
  7044. ChargeTypeId: Number(chargeTypeId),
  7045. ChargeIndex: chargeIndex,
  7046. Percentage: Number(percent),
  7047. FixedAmount: Number(value),
  7048. ApplyWhole: appliedOnWhole,
  7049. Description: desc,
  7050. TotalAmount: Number(totalamount),
  7051. LedgerId: Number(ledgerId),
  7052. TaxGroupId: Number($(this).find(".hfProdTax").val())
  7053. });
  7054. }
  7055. }
  7056. });
  7057. $(".expense-row").each(function () {
  7058. if ($(this).find(".selectedItemId").val() != undefined) {
  7059. if ($(this).find(".hfSelectedChargeId").val() != "" && $(this).find(".hfSelectedChargeId").val() != "0") {
  7060. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  7061. let ChargeId = $(this).find(".hfSelectedChargeId").val();
  7062. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  7063. var percent = $(this).find(".exppercentage").val();
  7064. var value = $(this).find(".expfixedvalue").val();
  7065. var desc = $(this).find(".expenseDesc").val();
  7066. var totalamount = $(this).find(".expense-row-total").html();
  7067. var ledgerId = $(this).find(".hf_Account").val();
  7068. if (Number(value) != 0 || Number(percent)) {
  7069. ChargeList.push({
  7070. InvoiceChargeId: Number(invoicechargeid),
  7071. ChargeId: Number(ChargeId),
  7072. ChargeTypeId: Number(chargeTypeId),
  7073. Percentage: Number(percent),
  7074. FixedAmount: Number(value),
  7075. ApplyWhole: true,
  7076. Description: desc,
  7077. TotalAmount: Number(totalamount),
  7078. LedgerId: Number(ledgerId),
  7079. TaxGroupId: Number($(this).find(".hfProdTax").val())
  7080. });
  7081. }
  7082. }
  7083. }
  7084. });
  7085. return ChargeList;
  7086. }
  7087. getobj() {
  7088. var item = Number($(".selectedItemId").val());
  7089. var inventorytypeid = 0;
  7090. var AdjustmentAccountId = 0;
  7091. var isqtyavail = true;
  7092. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
  7093. Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItem(item).then(function (response) {
  7094. inventorytypeid = response.result.InventoryTypeId;
  7095. $(".InvoiceItems").find(".remove_item").remove();
  7096. InvoiceItem.Instance().update_total();
  7097. InvoiceItem.Instance().TotalAdjustment();
  7098. if ($("#chk_tcsapplied").prop("checked") == true && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && InvoiceItem.Instance().EnableTenantTcs == false) {
  7099. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7100. $(".InvoiceItems").append("<div class='item-row added-row InvoiceitemRow-0'></div>");
  7101. return false;
  7102. }
  7103. var CompanyName = $(".txtAutoComplete_orgcontactid").text();
  7104. if (CompanyName == "") {
  7105. $(".hfAutoCompleteId_orgcontactid").val(0);
  7106. }
  7107. var Adjustment = $('#txt_Adjustment').val();
  7108. if ($('#chk_AutoAdjustment').is(':checked')) {
  7109. if ($('#hf_AdjustmentAccountId').val() == 0) {
  7110. MessageHelper.Instance().showError("Please Select Adjustment Account", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7111. return false;
  7112. }
  7113. InvoiceItem.Instance().TotalAdjustment();
  7114. Adjustment = $('#txt_Adjustment').val();
  7115. AdjustmentAccountId = Number($("#txt_AdjustmentAccountName").val());
  7116. }
  7117. });
  7118. });
  7119. if ($('#chk_AutoAdjustment').is(':checked')) {
  7120. if ($('#hf_AdjustmentAccountId').val() == 0) {
  7121. MessageHelper.Instance().showError("Please Select Adjustment Account", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7122. return false;
  7123. }
  7124. else
  7125. AdjustmentAccountId = Number($("#txt_AdjustmentAccountName").val());
  7126. }
  7127. let isemptyrow = false;
  7128. let rownotexist = true;
  7129. let itemarray = [];
  7130. let emptysplitrow = false;
  7131. let itemname = "";
  7132. var IsUnitPriceZero = false;
  7133. $(".InvoiceItems").find(".item-addedrow").each(function () {
  7134. rownotexist = false;
  7135. if (!$(this).hasClass('SplitItem')) {
  7136. if ($(this).find(".selectedItemId").val() == undefined || $(this).find(".selectedItemId").val() == 0) {
  7137. isemptyrow = true;
  7138. }
  7139. if ($(this).find(".hfProdTax").val() == "0" || $(this).find(".hf_Account").val() == "0") {
  7140. itemarray.push($(this));
  7141. }
  7142. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && (InvoiceItem.Instance().AutoDc == true || InvoiceItem.Instance().OrderSettingId == 2)) {
  7143. inventorytypeid = Number($(this).find("#inventorytypeid").val());
  7144. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  7145. if ((Number($(this).find('.prodQuantity').val()) > Number($(this).find('.prodAvail').text())) && $(".hdn_invoiceid").val() == "0" && inventorytypeid != 2) {
  7146. isqtyavail = false;
  7147. }
  7148. else {
  7149. let Qty = Number($(this).find('.prodQuantity').val());
  7150. let AvQty = Number($(this).find('.prodAvail').text()) + Number($(this).find('.Qty').val());
  7151. if (Qty > AvQty && inventorytypeid != 2)
  7152. isqtyavail = false;
  7153. }
  7154. }
  7155. }
  7156. }
  7157. else {
  7158. if (InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.itemId == Number($(this).find(".selectedItemId").val()))) {
  7159. }
  7160. else {
  7161. emptysplitrow = true;
  7162. itemname = $(this).find(".prodName").text();
  7163. }
  7164. }
  7165. var UnitPrice = Number($(this).find(".prodPrice").val());
  7166. if (UnitPrice == 0 && $(this).find(".hf_IsBOM").val() == "false" && $(this).find(".hf_IsFoc").val() == "false") {
  7167. IsUnitPriceZero = true;
  7168. }
  7169. });
  7170. if (!isqtyavail) {
  7171. MessageHelper.Instance().showError("Please check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7172. return false;
  7173. }
  7174. if (isemptyrow) {
  7175. MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7176. return false;
  7177. }
  7178. if (rownotexist) {
  7179. MessageHelper.Instance().showError("Please Add Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7180. return false;
  7181. }
  7182. if (emptysplitrow) {
  7183. MessageHelper.Instance().showError("Please Select Mrp/Batch for the Item: " + itemname, $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7184. return false;
  7185. }
  7186. let couponitemrow = false;
  7187. $(".addednetdiscount-row").each(function () {
  7188. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  7189. if (($(this).find(".percentage").val() == "0" || $(this).find(".percentage").val() == "") && ($(this).find(".fixedvalue").val() == 0 || $(this).find(".fixedvalue").val() == ""))
  7190. isemptyrow = true;
  7191. }
  7192. if ($(this).find(".selectedItemId").val() == "0" || $(this).find(".selectedItemId").val() == undefined)
  7193. couponitemrow = true;
  7194. });
  7195. if (isemptyrow) {
  7196. MessageHelper.Instance().showError("Please enter percentage or value for coupon item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7197. return false;
  7198. }
  7199. if (IsUnitPriceZero) {
  7200. MessageHelper.Instance().showError("Item UnitPrice should not be zero.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7201. return false;
  7202. }
  7203. if (couponitemrow) {
  7204. MessageHelper.Instance().showError("Please Select Coupon Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7205. return false;
  7206. }
  7207. var wallets = InvoiceItem.Instance().getwalletinvoiceditems();
  7208. var invItems = InvoiceItem.Instance().getInvoiceItems();
  7209. if (invItems.length == 0) {
  7210. MessageHelper.Instance().showError("You Should Add atleast One Item.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7211. return false;
  7212. }
  7213. else {
  7214. var qtyresult = invItems.find(x => x.AccountId == 0) ? true : false;
  7215. if (qtyresult == true) {
  7216. for (var i = 0; i < itemarray.length; i++) {
  7217. itemarray[i].find(".div_MoreDetails").removeClass("hidden");
  7218. }
  7219. MessageHelper.Instance().showError("Account Not Configured for the item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7220. return false;
  7221. }
  7222. var qty = invItems.find(x => x.Quantity == 0) ? true : false;
  7223. if (qty == true) {
  7224. MessageHelper.Instance().showError("Item quantity should not be zero.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7225. return false;
  7226. }
  7227. var TaxGroup = invItems.find(x => x.TaxGroupId == 0) ? true : false;
  7228. if (TaxGroup == true) {
  7229. for (var i = 0; i < itemarray.length; i++) {
  7230. itemarray[i].find(".div_MoreDetails").removeClass("hidden");
  7231. }
  7232. MessageHelper.Instance().showError("TaxGroup Not Configured for the item.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7233. return false;
  7234. }
  7235. }
  7236. var billingAddressId = $(".hfAutoCompleteId_billtoaddressid").val();
  7237. if (billingAddressId == null)
  7238. billingAddressId = $("#hfId_billtoaddressid").val();
  7239. var invoiceid = $(".hdn_invoiceid").val();
  7240. let refInvoiceId = 0;
  7241. if ($(".hdn_refinvoiceid").val() != undefined && Number($(".hdn_refinvoiceid").val()) != 0)
  7242. refInvoiceId = Number($(".hdn_refinvoiceid").val());
  7243. if (invoiceid == undefined)
  7244. invoiceid = 0;
  7245. if (($(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "3") && $("#hf_AppSettingName").val() == "Create Return") {
  7246. invoiceid = 0;
  7247. if (refInvoiceId == 0) {
  7248. refInvoiceId = Number($(".hdn_invoiceid").val());
  7249. $(".hdn_refinvoiceid").val($(".hdn_invoiceid").val());
  7250. }
  7251. $(".hdn_invoiceid").val("0");
  7252. $(".hdn_journalno").val("0");
  7253. }
  7254. let orgcontactid = $(".txtAutoComplete_orgcontactid").val();
  7255. var dcid = InvoiceItem.Instance().dcid;
  7256. if (invoiceid == 0 && ($(".hdn_invoicetypeid").val() == '3' || $(".hdn_invoicetypeid").val() == '4' || $(".hdn_invoicetypeid").val() == '7' || $(".hdn_invoicetypeid").val() == '6')) {
  7257. dcid = 0;
  7258. }
  7259. var orderid = InvoiceItem.Instance().orderid;
  7260. if (orderid == undefined || orderid == 0) {
  7261. orderid = 0;
  7262. }
  7263. var ClaimId = InvoiceItem.Instance().ClaimId;
  7264. if (ClaimId == undefined || ClaimId == 0) {
  7265. ClaimId = 0;
  7266. }
  7267. else
  7268. orderid = ClaimId;
  7269. var branchid = 0;
  7270. $(".txt_RefNo").val() == "null" ? $(".txt_RefNo").val("") : $(".txt_refno").val();
  7271. var description = $(".divCustomProperties_systemnotes").find("textarea").val();
  7272. if ($('.txt_tcsadjustment').val() == "")
  7273. $('.txt_tcsadjustment').val(0);
  7274. if (Number($(".nettotal").html()) < 0) {
  7275. MessageHelper.Instance().showError("Invoice value should not be less than 0", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7276. return false;
  7277. }
  7278. var InvoiceObject = {
  7279. TotalAmount: Number($(".nettotal").html()),
  7280. InvoiceItems: invItems,
  7281. InvoiceCharges: InvoiceItem.Instance().getCharges(),
  7282. AutoAdjustment: Boolean($('#chk_AutoAdjustment').is(':checked')),
  7283. AutoDc: InvoiceItem.Instance().AutoDc,
  7284. InvItemTaxAdjustments: InvoiceItem.Instance().invItemTaxAdjustmentList,
  7285. JournalAlloc: wallets,
  7286. AdjustmentAccountId: Number($("#txt_AdjustmentAccountName").val()),
  7287. InvoiceId: Number(invoiceid),
  7288. RefInvoiceId: Number(refInvoiceId),
  7289. OrgContactId: Number(orgcontactid),
  7290. DeletedInvoiceId: InvoiceItem.Instance().deleted_invoiceItems,
  7291. IsOfferChargeApplied: InvoiceItem.Instance().isOfferChargeApplied,
  7292. };
  7293. return InvoiceObject;
  7294. }
  7295. saveInvoice() {
  7296. $(".InvoiceItems").find(".remove_item").remove();
  7297. InvoiceItem.Instance().update_total();
  7298. InvoiceItem.Instance().TotalAdjustment();
  7299. var inventorytypeid = 0;
  7300. var AdjustmentAccountId = 0;
  7301. var item = Number($(".selectedItemId").val());
  7302. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
  7303. Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItem(item).then(function (response) {
  7304. inventorytypeid = response.result.InventoryTypeId;
  7305. if ($("#chk_tcsapplied").prop("checked") == true && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && InvoiceItem.Instance().EnableTenantTcs == false) {
  7306. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7307. $(".InvoiceItems").append("<div class='item-row added-row InvoiceitemRow-0'></div>");
  7308. return false;
  7309. }
  7310. var CompanyName = $(".txtAutoComplete_orgcontactid").text();
  7311. if (CompanyName == "") {
  7312. $(".hfAutoCompleteId_orgcontactid").val(0);
  7313. }
  7314. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && (InvoiceItem.Instance().AutoDc == true || InvoiceItem.Instance().OrderSettingId == 2)) {
  7315. var isqtyavail = true;
  7316. $(".InvoiceItems").find(".item-addedrow").each(function () {
  7317. if (!$(this).hasClass('SplitItem')) {
  7318. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  7319. if (Number($(this).find('.prodQuantity').val()) > Number($(this).find('.prodAvail').text()) && inventorytypeid != 2) {
  7320. isqtyavail = false;
  7321. }
  7322. }
  7323. }
  7324. });
  7325. if (!isqtyavail) {
  7326. MessageHelper.Instance().showError("Please check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7327. return false;
  7328. }
  7329. }
  7330. });
  7331. });
  7332. var Adjustment = $('#txt_Adjustment').val();
  7333. var AdjustmentAccountId = 0;
  7334. if ($('#chk_AutoAdjustment').is(':checked')) {
  7335. if ($('#hf_AdjustmentAccountId').val() == 0) {
  7336. MessageHelper.Instance().showError("Please Select Adjustment Account", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7337. return false;
  7338. }
  7339. InvoiceItem.Instance().TotalAdjustment();
  7340. Adjustment = $('#txt_Adjustment').val();
  7341. AdjustmentAccountId = Number($("#txt_AdjustmentAccountName").val());
  7342. }
  7343. if (Number($('#txt_Adjustment').val()) != 0) {
  7344. if ($('#hf_AdjustmentAccountId').val() == 0) {
  7345. MessageHelper.Instance().showError("Please Select Adjustment Account", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7346. return false;
  7347. }
  7348. else
  7349. AdjustmentAccountId = Number($("#txt_AdjustmentAccountName").val());
  7350. }
  7351. let isemptyrow = false;
  7352. let rownotexist = true;
  7353. let itemarray = [];
  7354. let emptysplitrow = false;
  7355. let itemname = "";
  7356. $(".InvoiceItems").find(".item-addedrow").each(function () {
  7357. rownotexist = false;
  7358. if (!$(this).hasClass('SplitItem')) {
  7359. if ($(this).find(".selectedItemId").val() == undefined || $(this).find(".selectedItemId").val() == 0) {
  7360. isemptyrow = true;
  7361. }
  7362. if ($(this).find(".hfProdTax").val() == "0" || $(this).find(".hf_Account").val() == "0") {
  7363. itemarray.push($(this));
  7364. }
  7365. }
  7366. else {
  7367. if (InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.itemId == Number($(this).find(".selectedItemId").val()))) {
  7368. }
  7369. else {
  7370. emptysplitrow = true;
  7371. itemname = $(this).find(".prodName").text();
  7372. }
  7373. }
  7374. });
  7375. if (isemptyrow) {
  7376. MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7377. return false;
  7378. }
  7379. if (rownotexist) {
  7380. MessageHelper.Instance().showError("Please Add Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7381. return false;
  7382. }
  7383. if (emptysplitrow) {
  7384. MessageHelper.Instance().showError("Please Select Mrp/Batch for the Item: " + itemname, $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7385. return false;
  7386. }
  7387. let couponitemrow = false;
  7388. $(".addednetdiscount-row").each(function () {
  7389. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  7390. if (($(this).find(".percentage").val() == "0" || $(this).find(".percentage").val() == "") && ($(this).find(".fixedvalue").val() == 0 || $(this).find(".fixedvalue").val() == ""))
  7391. isemptyrow = true;
  7392. }
  7393. if ($(this).find(".selectedItemId").val() == "0" || $(this).find(".selectedItemId").val() == undefined)
  7394. couponitemrow = true;
  7395. });
  7396. if (isemptyrow) {
  7397. MessageHelper.Instance().showError("Please enter percentage or value for coupon item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7398. return false;
  7399. }
  7400. if (couponitemrow) {
  7401. MessageHelper.Instance().showError("Please Select Coupon Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7402. return false;
  7403. }
  7404. var wallets = InvoiceItem.Instance().getwalletinvoiceditems();
  7405. var invItems = InvoiceItem.Instance().getInvoiceItems();
  7406. if (invItems.length == 0) {
  7407. MessageHelper.Instance().showError("You Should Add atleast One Item.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7408. return false;
  7409. }
  7410. else {
  7411. var qtyresult = invItems.find(x => x.AccountId == 0) ? true : false;
  7412. if (qtyresult == true) {
  7413. for (var i = 0; i < itemarray.length; i++) {
  7414. itemarray[i].find(".div_MoreDetails").removeClass("hidden");
  7415. }
  7416. MessageHelper.Instance().showError("Account Not Configured for the item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7417. return false;
  7418. }
  7419. var qty = invItems.find(x => x.Quantity == 0) ? true : false;
  7420. if (qty == true) {
  7421. MessageHelper.Instance().showError("Item quantity should not be zero.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7422. return false;
  7423. }
  7424. var TaxGroup = invItems.find(x => x.TaxGroupId == 0) ? true : false;
  7425. if (TaxGroup == true) {
  7426. for (var i = 0; i < itemarray.length; i++) {
  7427. itemarray[i].find(".div_MoreDetails").removeClass("hidden");
  7428. }
  7429. MessageHelper.Instance().showError("TaxGroup Not Configured for the item.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7430. return false;
  7431. }
  7432. }
  7433. var PaymentTermName = $(".txtAutoComplete_paymentiermid").text();
  7434. var billingAddressId = $(".hfAutoCompleteId_billtoaddressid").val();
  7435. if (billingAddressId == null)
  7436. billingAddressId = $("#hfId_billtoaddressid").val();
  7437. var invoiceid = $(".hdn_invoiceid").val();
  7438. let refInvoiceId = 0;
  7439. if (invoiceid == undefined)
  7440. invoiceid = 0;
  7441. if (($(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "3") && $("#hf_AppSettingName").val() == "Create Return") {
  7442. invoiceid = 0;
  7443. refInvoiceId = Number($(".hdn_invoiceid").val());
  7444. $(".hdn_refinvoiceid").val($(".hdn_invoiceid").val());
  7445. $(".hdn_invoiceid").val("0");
  7446. $(".hdn_journalno").val("0");
  7447. }
  7448. let orgcontactid = $(".txtAutoComplete_orgcontactid").val();
  7449. var dcid = InvoiceItem.Instance().dcid;
  7450. if (invoiceid == 0 && ($(".hdn_invoicetypeid").val() == '3' || $(".hdn_invoicetypeid").val() == '4' || $(".hdn_invoicetypeid").val() == '7' || $(".hdn_invoicetypeid").val() == '6')) {
  7451. dcid = 0;
  7452. }
  7453. var orderid = InvoiceItem.Instance().orderid;
  7454. if (orderid == undefined || orderid == 0) {
  7455. orderid = 0;
  7456. }
  7457. var ClaimId = InvoiceItem.Instance().ClaimId;
  7458. if (ClaimId == undefined || ClaimId == 0) {
  7459. ClaimId = 0;
  7460. }
  7461. else
  7462. orderid = ClaimId;
  7463. var branchid = 0;
  7464. if ((ClaimId != 0 || orderid != 0) && InvoiceItem.Instance().dcid == 0)
  7465. for (let obj of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) {
  7466. if (obj.Key === "hf_" + $("#hfLayout_InstalledPageId").val() + "_branchid")
  7467. branchid = InvoiceItem.Instance().orderid = Number(obj.Value);
  7468. }
  7469. else
  7470. branchid = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  7471. $(".txt_RefNo").val() == "null" ? $(".txt_RefNo").val("") : $(".txt_refno").val();
  7472. var description = $(".divCustomProperties_systemnotes").find("textarea").val();
  7473. if ($('.txt_tcsadjustment').val() == "")
  7474. $('.txt_tcsadjustment').val(0);
  7475. var InvoiceObject = {
  7476. PaymentTermName: PaymentTermName,
  7477. BranchId: branchid,
  7478. TotalAmount: Number($(".nettotal").html()),
  7479. InvoiceItems: invItems,
  7480. InvoiceCharges: InvoiceItem.Instance().getCharges(),
  7481. AutoAdjustment: Boolean($('#chk_AutoAdjustment').is(':checked')),
  7482. AutoDc: InvoiceItem.Instance().AutoDc,
  7483. InvItemTaxAdjustments: InvoiceItem.Instance().invItemTaxAdjustmentList,
  7484. JournalAlloc: wallets,
  7485. AdjustmentAccountId: Number($("#txt_AdjustmentAccountName").val()),
  7486. InvoiceId: Number(invoiceid),
  7487. RefInvoiceId: Number(refInvoiceId),
  7488. OrgContactid: orgcontactid,
  7489. DeletedInvoiceId: InvoiceItem.Instance().deleted_invoiceItems,
  7490. IsOfferChargeApplied: InvoiceItem.Instance().isOfferChargeApplied,
  7491. };
  7492. return InvoiceObject;
  7493. }
  7494. addRow() {
  7495. let isemptyrow = false;
  7496. $(".InvoiceItems").find(".item-addedrow").each(function () {
  7497. if (!$(this).hasClass('SplitItem')) {
  7498. if ($(this).find(".selectedItemId").val() == undefined || $(this).find(".selectedItemId").val() == 0) {
  7499. isemptyrow = true;
  7500. }
  7501. }
  7502. });
  7503. if (isemptyrow) {
  7504. MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  7505. return false;
  7506. }
  7507. var emptyRow = {
  7508. orderItemId: 0,
  7509. invoiceItemId: 0,
  7510. itemName: "",
  7511. itemId: 0,
  7512. itemSKU: "",
  7513. unitName: "",
  7514. packSize: 0,
  7515. packCount: 0,
  7516. packs: 0,
  7517. quantity: 0,
  7518. availPacks: 0,
  7519. availQty: 0,
  7520. listPrice: 0,
  7521. description: "",
  7522. taxGroupName: "",
  7523. taxGroupId: 0,
  7524. isTaxInclusive: $("#hf_istaxinclusive").val(),
  7525. addlDiscountPercent: 0,
  7526. addlDiscountValue: 0,
  7527. creditNote: 0,
  7528. priceListId: 0,
  7529. batchId: 0,
  7530. unitPrice: 0,
  7531. invoiceallocations: null,
  7532. exciseInvoiceItem: null,
  7533. accountId: 0,
  7534. accountName: "",
  7535. walletId: 0,
  7536. Adjustment: 0,
  7537. IsFoc: false,
  7538. TariffNo: "",
  7539. exciseAmount: 0,
  7540. discountName: "",
  7541. discountId: 0,
  7542. refNo: "",
  7543. DiscountGroupId: 0,
  7544. DiscountGroupName: '',
  7545. RefInvoiceItemId: 0,
  7546. MrpId: 0,
  7547. taxAdjustment: 0,
  7548. assesableAdjustment: 0,
  7549. inventoryTypeId: 0,
  7550. dcItemId: 0,
  7551. TotalRowAmount: 0,
  7552. maxQty: 0,
  7553. OfferItemId: 0
  7554. };
  7555. InvoiceItem.instance.addDataRow(emptyRow, false);
  7556. }
  7557. addDataRow(row, IsSplitItem) {
  7558. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/compact/components/details/details.js", function () {
  7559. });
  7560. this.rowIndex = $(".InvoiceItems").find(".item-addedrow").length + 1;
  7561. var bg = "";
  7562. if (row.packSize == 0)
  7563. row.packSize = 1;
  7564. if (row.packCount == 0)
  7565. row.packCount = 1;
  7566. if (row.quantity == 0)
  7567. row.quantity = row.packCount * row.packs * row.packSize;
  7568. var price = row.unitPrice;
  7569. if (row.unitPrice == 0)
  7570. price = row.listPrice;
  7571. var currenttaxgroupid = 0;
  7572. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_IsRetun').val() == "1") {
  7573. row.invoiceallocations = null;
  7574. row.invoiceItemId = 0;
  7575. }
  7576. if ($('#hfInv_IsRetun').val() == "1")
  7577. row.invoiceItemId = 0;
  7578. var zeroBilled = "";
  7579. if (price == 0)
  7580. zeroBilled = "bg-danger";
  7581. var zeroQtyText = "";
  7582. var zeroQtyDiv = "bg-light";
  7583. let invoiceid = $(".hdn_invoiceid").val();
  7584. if (invoiceid == "0") {
  7585. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && row.itemId != 0 && row.IsFoc == false) {
  7586. if (row.availQty == 0) {
  7587. row.quantity = 0;
  7588. zeroQtyText = "text-danger";
  7589. zeroQtyDiv = "bg-danger";
  7590. }
  7591. else if (row.availQty < row.quantity) {
  7592. row.quantity = row.availQty;
  7593. }
  7594. }
  7595. }
  7596. var readonlyQty = "";
  7597. var ManageInvoice = 2;
  7598. var AutoDc = false;
  7599. var ManageInvoiceTax = 2;
  7600. var readonlyPrice = "";
  7601. var readonlyDisc = "";
  7602. var readonlyTax = "";
  7603. if (ManageInvoice == 1 && AutoDc == false) {
  7604. readonlyQty = "readonly";
  7605. readonlyPrice = "readonly";
  7606. readonlyDisc = "readonly";
  7607. readonlyTax = "disabled";
  7608. }
  7609. if ($('.hdn_invoicetypeid').val() == "1" && ManageInvoiceTax == 1 && AutoDc == false) {
  7610. readonlyTax = "readonly";
  7611. }
  7612. if (row.inventoryTypeId == "2") {
  7613. readonlyQty = "";
  7614. readonlyPrice = "";
  7615. }
  7616. var activeDiscVal = "";
  7617. var activeDiscPercent = "";
  7618. var activeDiscMul = "";
  7619. var activeDiscText = "";
  7620. var discValue = 0;
  7621. if (row.addlDiscountPercent > 0) {
  7622. discValue = row.addlDiscountPercent;
  7623. activeDiscPercent = "active";
  7624. activeDiscText = "%";
  7625. }
  7626. else if (row.addlDiscountValue > 0 && row.DiscountGroupId > 0) {
  7627. discValue = row.addlDiscountValue;
  7628. activeDiscMul = "active";
  7629. activeDiscText = "Mul";
  7630. }
  7631. else {
  7632. discValue = row.addlDiscountValue;
  7633. activeDiscVal = "active";
  7634. activeDiscText = "Val";
  7635. }
  7636. var itemNameClass = "floating-label-form-group";
  7637. if (row.invoiceItemId != 0)
  7638. itemNameClass = "";
  7639. var mt = "";
  7640. if (row.invoiceItemId != 0) {
  7641. mt = "mt-5";
  7642. }
  7643. if (row.orderItemId != 0) {
  7644. mt = "mt-10";
  7645. }
  7646. let AlternateUnitId = row.AlternateUnitId;
  7647. let DefaultSize = row.DefaultSize;
  7648. if (AlternateUnitId == undefined) {
  7649. AlternateUnitId = 0;
  7650. }
  7651. if (row.ParentBOMItemId == null)
  7652. row.ParentBOMItemId = 0;
  7653. if (row.inventoryTypeId != 5 && row.inventoryTypeId != 6 && row.inventoryTypeId != 7) {
  7654. var IsBom = "";
  7655. if (row.IsBoMItem == true && row.IsBoMItem != undefined) {
  7656. IsBom = "hidden";
  7657. }
  7658. var isbomitem = false;
  7659. if (row.ParentBOMItemId != 0)
  7660. isbomitem = true;
  7661. var html = '<div id="div_itemAddedRow_' + this.rowIndex + '" class="item-row item-addedrow ' + bg + '">' +
  7662. '<div class="row mx-0 justify-content-between align-items-end ' + IsBom + ' divItemRow_' + row.itemId + ' ">' +
  7663. '<div class="col-lg-4 col-md-6 my-15 position-relative"> <div class="position-absolute r-0 z-index-1 sales-special-offers"><a class="btn_offer hidden" > <span class="btn btn-outline-primary btn-xs font-10 line-height-12 mb-1 count" > offer </span></a> <a class="btn_specialPrice hidden"><span class="btn btn-outline-blue btn-xs font-10 line-height-12 mb-1 count">SP</span></a></div>' +
  7664. '<div class=" item-name min-padding" style="margin-left:20px;">' +
  7665. '<lable for="lbl_itemname" class="d-md-none">Item Name</lable>' +
  7666. '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  7667. '<input type="hidden" class="orderItemId" value="' + row.orderItemId + '" />' +
  7668. '<input type="hidden" class="dcItemId" value="' + row.dcItemId + '" />' +
  7669. '<input type="hidden" class="selectedInvoiceItemId" value="' + row.invoiceItemId + '" />' +
  7670. '<input type="hidden" class="refInvoiceItemId" value="' + row.RefInvoiceItemId + '" />' +
  7671. '<input type="hidden" class="selectedItemId" id="hf_txtitem_' + this.rowIndex + '" value="' + row.itemId + '" />' +
  7672. '<input type="hidden" id="selectedItemId" value="' + row.itemId + '" />' +
  7673. '<input type="hidden" id="inventorytypeid" value="' + row.itemId + '" />' +
  7674. '<input type="hidden" class="selectedItemName" value="' + row.itemname + '" />' +
  7675. '<input type="hidden" class="hfMrpId" value="' + row.MrpId + '" />' +
  7676. '<input type="hidden" class="offerapplied" value="0" />' +
  7677. '<input type="hidden" class="refNo" value="' + row.refNo + '"/>' +
  7678. '<input type="hidden" class="description" value="' + row.description + '"/>' +
  7679. '<input type="hidden" class="IsExchangeItem" value="' + row.ExchangeItem + '" />' +
  7680. '<input type="hidden" class="maxQty" value="' + row.maxQty + '" />' +
  7681. '<input type="hidden" class="Qty" value="' + row.quantity + '" />' +
  7682. '<input type="hidden" class="hfAccountId" value="' + row.accountId + '"/>' +
  7683. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="' + row.taxAdjustment + '" />' +
  7684. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="' + row.assesableAdjustment + '" />' +
  7685. '<input type="hidden" class="hfoldItemId" value="' + row.itemId + '"/>' +
  7686. '<input type="hidden" class="hf_IsFoc" value="' + row.IsFoc + '"/>' +
  7687. '<input type="hidden" class="hf_UnitPrice" value="' + price + '"/>' +
  7688. '<input type="hidden" class="hf_AlternateUnitId" value="' + AlternateUnitId + '"/>' +
  7689. '<input type="hidden" class="hf_AlternateUnitName" value="' + row.AlternateUnitName + '"/>' +
  7690. '<input type="hidden" class="hf_UnitName" value="' + row.unitName + '"/>' +
  7691. '<input type="hidden" class="hf_DefaultSize" value="' + DefaultSize + '"/>' +
  7692. '<input type="hidden" class="hf_IsBOM" value="' + isbomitem + '"/>' +
  7693. '<input type="hidden" class="hf_ParentBOMItemId" value="' + row.ParentBOMItemId + '"/>' +
  7694. '<input type="hidden" class="hf_IsMultipleUOM" value="' + row.IsMultipleUOMs + '"/>' +
  7695. '<input type="hidden" class="hf_IsManualUOM" value="' + row.IsManualUOM + '"/>' +
  7696. '<input type="hidden" class="hf_ConversionQuantity" value="' + row.ConversionQuantity + '"/>' +
  7697. '<input type="hidden" class="hf_IsSpecialPrice" value="' + row.IsSpecialPrice + '"/>' +
  7698. '<input type="hidden" class="hf_AddtionalDiscount" value="0"/>';
  7699. if (row.IsFoc == true) {
  7700. html += '<input type="hidden" class="hfOfferedItemId" value="' + row.OfferItemId + '"/>';
  7701. }
  7702. html += '<div class="item-name-wrap">' +
  7703. '<a class="no-border bg-white delete" href = "javascript:;" title = "Remove row" style = "" > <i class="fa fa-trash-o fa-lg mt-15 mr-2" style="margin-left:-25px;color:red"></i></a>';
  7704. if (row.invoiceItemId != 0) {
  7705. var itemName = row.itemSKU + ' - ' + row.itemName;
  7706. if (row.ExchangeItem)
  7707. itemName = '(Exchange) ' + row.itemSKU + ' - ' + row.itemName;
  7708. html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
  7709. }
  7710. else {
  7711. var itemName = "";
  7712. if (row.ExchangeItem)
  7713. itemName = '(Exchange) ' + row.itemName;
  7714. else if (row.itemName != "" && row.itemSKU != "") {
  7715. itemName = row.itemSKU + '-' + row.itemName;
  7716. html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
  7717. }
  7718. else if (row.itemName != "") {
  7719. itemName = row.itemName;
  7720. html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
  7721. }
  7722. else {
  7723. html += '<select class="form-control prodName" value="" id="txt_item_' + this.rowIndex + '" placeholder=" Select the item to Invoice" style="width:100%;" id="txtItem"></select>';
  7724. }
  7725. }
  7726. html += '</div>' +
  7727. '</div></div>' +
  7728. '<div class="col-lg-2 col-md-6 pr-0 my-15">' +
  7729. '<div class="floating-label-form-group text-center border-left-0">' +
  7730. '<lable for="lbl_qty" class="d-md-none">Qty</lable>' +
  7731. '<input type="text" class="prodQuantity text-center ' + zeroQtyText + ' form-control" placeholder="0.00" inputmode="numeric" value="' + row.quantity + '" ' + readonlyQty + ' />' +
  7732. '</div>' +
  7733. '</div>' +
  7734. '<div class="col-lg-2 col-md-4 div_UnitPrice my-15">' +
  7735. '<div class="floating-label-form-group min-padding text-center pl-15 border-left-0 "><lable for="lbl_unitprice" class="d-md-none">Unit Price</lable>';
  7736. var readonly = "";
  7737. html += '<input type="text" class="prodPrice text-center form-control" placeholder="0.00" inputmode="numeric" value="' + price + '" ' + readonlyPrice + ' />';
  7738. html += '</div></div>' +
  7739. '<div class="col-lg-2 col-md-4 div_SplitInvoiceItem my-15 hidden"><div class="mt-20 text-center"><a href="javascript:;" class="mr-10"><span id="spn_InvoiceItem_' + this.rowIndex + '" class="spn_InvoiceItem" style="text-decoration:underline;">Select</span></a></div></div>' +
  7740. '<div class="col-lg-2 col-md-4 my-15 div_Discount"> ' +
  7741. '<div class="floating-label-form-group text-center">' +
  7742. '<lable for="lbl_disc" class="d-md-none">Disc.</lable>' +
  7743. '<input type="hidden" id="hfProdDiscountGroupId" value="' + row.DiscountGroupId + '" />' +
  7744. '<input type="hidden" id="hfProdDiscountGroupName" value="' + row.DiscountGroupName + '" />' +
  7745. '<input type="hidden" id="hfProdDiscountList" value="" />' +
  7746. '<input type="hidden" id="hfProdDiscountApplyTypes" value="" />' +
  7747. '<div class="input-group">' +
  7748. '<input type="text" id="inv_txtdiscount" placeholder="0.00" class="form-control inv_txtaddldiscount" inputmode="numeric" value="' + discValue + '" ' + readonlyDisc + '>' +
  7749. '<div class="input-group-btn">' +
  7750. '<select class="btnInvoice_DiscType btn_inv_DiscType mt-10 border-blue"><option value="Val">Val</option><option value="%">%</option></select>' +
  7751. '</div>' +
  7752. '</div>' +
  7753. '</div>' +
  7754. '</div>' +
  7755. '<div class="col-lg-2 col-md-4 my-15">' +
  7756. '<input type="hidden" class="hfDiscountedAmount" value="0" />' +
  7757. '<input type="hidden" class="hfRowTotalAdjustment" value="' + row.Adjustment + '" />' +
  7758. '<input type="hidden" class="hfAssesableAdjustment" value="" />' +
  7759. '<input type="hidden" class="hfTaxAdjustment" value="" />';
  7760. if (($(".hdn_invoicetypeid").val() == "2") && invoiceid != 0) {
  7761. html += '<a href="javascript:;" class=Adjustmentrow><input type="text" class="hfRowTotalwithAdjustment form-control txtRowTotalwithAdjustment text-right" value="0" style="color:#5ba8fb;cursor:pointer" disabled/></a>';
  7762. html += '<a href="javascript:;" class="hidden" onclick="javascript: InvoiceItem.Instance().editInvItemTaxAllocs(' + row.invoiceItemId + ',' + row.taxGroupId + ',' + row.itemId + ',' + row.orderItemId + ')"><input type="text" style="color:#5ba8fb;text-decoration:underline;cursor:pointer" class="hfRowTotal form-control txtRowTotal text-right" value="0" /></a>';
  7763. }
  7764. else {
  7765. html += '<p class="pull-right mt-10 text-center"><lable for="lbl_disc" class="d-md-none mr-1">Total:</lable><strong><input type="hidden" class="hfRowTotal" value="0" /><span class="prodTotalPrice">0.00</span></strong></p>';
  7766. }
  7767. html += '</div>' +
  7768. '</div>' +
  7769. '<div class="row"> <span class="col-sm-4"> <p class="ml-35 text-warning ItemConversion"> </p> </span>' +
  7770. '<span class="col-sm-2 text-center SelectedUOMName pl-50"> </span>' +
  7771. '<span class="col-sm-6 text-right UOMCalc"> </span></div>' +
  7772. '<div class="hidden div_MoreDetails clear mt-5 bg-light">' +
  7773. '<div class="row align-items-center mx-5 pt-10">' +
  7774. '<div class="col-lg-2 col-md-4 my-15">' +
  7775. '<div class="floating-label-form-group Desc">' +
  7776. '<label for="from_lbl_Description" id="lbl_Description">Description</label>' +
  7777. '<input type="text" id="txt_Description" data-isdynamic="false" class="form-control floating-label-control prodDesc" data-placeholder="Enter Description" placeholder="Description" data-label="Description"/>' +
  7778. '</div>' +
  7779. '</div>' +
  7780. '<div class="col-lg-2 col-md-4 my-15 hidden" id="div_MultipleUOMs">' +
  7781. '<div class="floating-label-form-group-with-value">' +
  7782. '<label for="from_lbl_UOM" id="lbl_Output">UOM</label>' +
  7783. '<div class="input-group">' +
  7784. '<select class="form-control type-control value-control dropdown_MultipleUOMs ddl_MultipleUOMs" placeholder = "Select UOM" data - placeholder="Select UOM" data-label="UOM" data-isparent="false"></select>' +
  7785. '</div></div>' +
  7786. '</div>' +
  7787. '<div class="col-lg-2 col-md-4 my-15">' +
  7788. '<div class="floating-label-form-group-with-value">' +
  7789. '<label for="from_lbl_Output" id="lbl_Output">Tax Group<span class="text-danger">*</span></label>' +
  7790. '<div class="input-group">';
  7791. if (row.taxGroupId != 0) {
  7792. html += '<select type="text" data-isdynamic="false" class="form-control text-control ui-autocomplete prodTax ' + readonlyTax + '" value="' + row.taxGroupName + '" data-label="Output" id="txt_prodTax_' + this.rowIndex + '" data-placeholder="Output @ 18%" placeholder="Output" style="width:100%;"></select>' +
  7793. '<input type="hidden" id="hfProdTaxPercent_' + this.rowIndex + '" class="hfProdTaxPercent" value="0" />' +
  7794. '<input type="hidden" id="hfProdTax_' + this.rowIndex + '" class="hfProdTax hidden" value="' + row.taxGroupId + '"/>' +
  7795. '<input type="hidden" class="txtProdTax hidden" value="' + row.taxGroupName + '"/>';
  7796. }
  7797. else {
  7798. html += '<select type="text" data-isdynamic="false" class="form-control text-control select2-hidden-accessible prodTax ' + readonlyTax + '" id="txt_prodTax_' + this.rowIndex + '" data-label="Output" data-placeholder="Output @ 18%" placeholder="Output" style="width:100%;" id="prodTax"></select>' +
  7799. '<input type="hidden" id="hfProdTaxPercent_' + this.rowIndex + '" class="hfProdTaxPercent" value="0" />' +
  7800. '<input type="hidden" id="hfProdTax_' + this.rowIndex + '" class="hfProdTax hidden" value="0"/>' +
  7801. '<input type="hidden" class="txtProdTax hidden" value=""/>';
  7802. }
  7803. html += '</div>' +
  7804. '</div>' +
  7805. '</div>' +
  7806. '<div class="col-lg-3 col-md-4 my-15">' +
  7807. '<div class="floating-label-form-group-with-value">' +
  7808. '<label for="from_lbl_Account" id="lbl_Account">Account<span class="text-danger">*</span></label>';
  7809. if (row.accountId != 0) {
  7810. html += '<select data-isdynamic="false" class="form-control txt_Account ' + readonlyTax + '" data-placeholder="Account Number" placeholder="Account" data-label="Account" value="' + row.accountName + '" id="txt_Account_' + this.rowIndex + '" style="width:100%;" data-required="true"></select>' +
  7811. '<input type="hidden" id="hf_Account_' + this.rowIndex + '" class="hf_Account" value="' + row.accountId + '" />' +
  7812. '<input type="hidden" id="txt_AccountName_' + this.rowIndex + '" class="txt_AccountName" value="' + row.accountName + '"/>';
  7813. }
  7814. else {
  7815. html += '<select data-isdynamic="false" class="form-control text-control select2-hidden-accessible txt_Account ' + readonlyTax + '" data-placeholder="Account Number" placeholder="Account" id="txt_Account_' + this.rowIndex + '" data-label="Account" style="width:100%;"></select>' +
  7816. '<input type="hidden" id="hf_Account_' + this.rowIndex + '" class="hf_Account" value="0" />' +
  7817. '<input type="hidden" id="txt_AccountName_' + this.rowIndex + '" class="txt_AccountName" value=""/>';
  7818. }
  7819. html += '</div>' +
  7820. '</div>' +
  7821. '<div class="col-lg-3 col-auto align-seld-end ml-auto text-right">' +
  7822. '<label for="from_lbl_Avalilability" id="lbl_Avalilability" class="text-dark mb-0 font-weight-bold mr-10">Availability :</label>' +
  7823. '<span class="prodAvail">' + row.availQty + '</span>' +
  7824. '</div>' +
  7825. '</div>' +
  7826. '<div class="row ml-5 mr-5">' +
  7827. '<div class="col-md-2"> </div>' +
  7828. '</div>' +
  7829. '<div class="row">' +
  7830. '<div class="col-md-12">' +
  7831. '<div class="col-md-3 form-group div_Mrp hidden">' +
  7832. '<div class="floating-label-form-group floating-label focus">' +
  7833. '<input type="hidden" class="hf_PriceList" value="' + row.priceListId + '" />' +
  7834. '<label for="from_lbl_MRP" id="lbl_MRP">MRP</label>' +
  7835. '<input type="text" data-isdynamic="false" class="form-control floating-label-control txt_MRP" data-placeholder="53" placeholder="MRP" data-label="MRP" />' +
  7836. '</div>' +
  7837. '</div>' +
  7838. '</div>' +
  7839. '<div class="orderitemlist"></div>' +
  7840. '</div><div class="accountRow"></div>';
  7841. $(".item-row:last").after(html);
  7842. var element = $(".item-addedrow:last");
  7843. if (IsSplitItem == true) {
  7844. element.addClass('SplitItem');
  7845. }
  7846. InvoiceItem.Instance().loadTaxGroupAutoComplete(element);
  7847. if (row.IsMultipleUOMs && $(".hdn_invoicetypeid").val() == "1") {
  7848. let MultipleUOMs = row.MultipleUoms;
  7849. let html = '<option value="0"> -- Select -- </option>';
  7850. for (var i = 0; i < MultipleUOMs.length; i++) {
  7851. html += '<option value="' + MultipleUOMs[i].SchemaDetailId + '">' + MultipleUOMs[i].AlternateUnitName + ' ( ' + MultipleUOMs[i].DefaultSize + ' ' + MultipleUOMs[i].DefaultUnitName + ' ) </option>';
  7852. }
  7853. element.find(".ddl_MultipleUOMs").html(html);
  7854. element.find("#div_MultipleUOMs").removeClass("hidden");
  7855. InvoiceItem.Instance().UOMs.push({
  7856. ItemId: row.itemId,
  7857. MultipleUOMs: MultipleUOMs
  7858. });
  7859. let SelectedUOM = Number(element.find(".hf_AlternateUnitId").val());
  7860. let DefaultSize = Number(element.find(".hf_DefaultSize").val());
  7861. if (SelectedUOM != 0) {
  7862. element.find(".ddl_MultipleUOMs").val(SelectedUOM);
  7863. let Qty = Number(element.find(".prodQuantity").val());
  7864. let NewQty = Qty / DefaultSize;
  7865. element.find(".prodQuantity").val(NewQty);
  7866. }
  7867. }
  7868. var txtTaxGroup = element.find(".prodTax");
  7869. var hfProdTax = element.find(".hfProdTax");
  7870. var hfAccount = element.find(".hf_Account");
  7871. var txtAccount = element.find(".txt_Account");
  7872. hfAccount.val(row.accountId);
  7873. hfProdTax.val(row.taxGroupId);
  7874. txtTaxGroup.append(new Option(row.taxGroupName, row.taxGroupId, true));
  7875. txtAccount.append(new Option(row.accountName, row.accountId, true));
  7876. InvoiceItem.instance.itemsAutoComplete(element);
  7877. InvoiceItem.instance.itemChange(element, element.find(".prodName").val(), element.find(".selectedItemId"));
  7878. $('.inv_txtaddldiscount').keypress(function (event) {
  7879. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  7880. if (element.find(".selectedItemId").val() == "0") {
  7881. Unibase.Platform.Forms.Components.FormViewer.Instance().showError("Please Select Item");
  7882. element.find('.inv_txtaddldiscount').val(0);
  7883. }
  7884. }
  7885. else {
  7886. event.preventDefault();
  7887. }
  7888. }).on('paste', function (event) {
  7889. var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
  7890. let val = event.originalEvent["clipboardData"].getData('text');
  7891. if (!numberRegex.test(val)) {
  7892. event.preventDefault();
  7893. return false;
  7894. }
  7895. });
  7896. $('.prodQuantity').keypress(function (event) {
  7897. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  7898. if (element.find(".selectedItemId").val() == "0") {
  7899. Unibase.Platform.Forms.Components.FormViewer.Instance().showError(" Please Select Item");
  7900. element.find(".prodQuantity").val(0);
  7901. }
  7902. }
  7903. else {
  7904. event.preventDefault();
  7905. }
  7906. }).on('paste', function (event) {
  7907. var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
  7908. let val = event.originalEvent["clipboardData"].getData('text');
  7909. if (!numberRegex.test(val)) {
  7910. event.preventDefault();
  7911. return false;
  7912. }
  7913. });
  7914. $('.prodPrice').keypress(function (event) {
  7915. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  7916. if (element.find(".selectedItemId").val() == "0") {
  7917. Unibase.Platform.Forms.Components.FormViewer.Instance().showError(" Please Select Item");
  7918. element.find('.prodPrice').val(0);
  7919. }
  7920. }
  7921. else {
  7922. event.preventDefault();
  7923. }
  7924. }).on('paste', function (event) {
  7925. var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
  7926. let val = event.originalEvent["clipboardData"].getData('text');
  7927. if (!numberRegex.test(val)) {
  7928. event.preventDefault();
  7929. return false;
  7930. }
  7931. });
  7932. element.find(".btnInvoice_DiscType option[value='" + activeDiscText + "']").prop("selected", true);
  7933. element.find(".prodPrice,.prodQuantity,.inv_txtaddldiscount").focusin(function () {
  7934. if (element.find($(".prodName")).val() != null || element.find($(".ItemName")).val() != null) {
  7935. $(".div_MoreDetails").addClass("hidden");
  7936. if (!element.parents(".item-row").hasClass('SplitItem'))
  7937. element.find(".div_MoreDetails").removeClass("hidden");
  7938. }
  7939. });
  7940. element.find(".prodName").focusin(function () {
  7941. $(".divMoreDetails").addClass("hidden");
  7942. });
  7943. if (row.description != null && row.description != '' && row.description != 'null') {
  7944. element.find('#txt_Description').val(row.description);
  7945. element.find('#txt_Description').parent(".Desc").addClass("floating-label-form-group-with-value");
  7946. }
  7947. InvoiceItem.Instance().bind(element, row.inventoryTypeId);
  7948. element.find("#inv_txtdiscount").change(function () {
  7949. if (!element.hasClass('SplitItem')) {
  7950. if (element.find(".btnInvoice_DiscType").val() == "%") {
  7951. if (Number(element.find("#inv_txtdiscount").val()) > 100) {
  7952. element.find("#inv_txtdiscount").val("100");
  7953. }
  7954. }
  7955. }
  7956. });
  7957. if (row.TotalRowAmount != 0) {
  7958. if ($(".hdn_invoicetypeid").val() == "2") {
  7959. element.find(".hfRowTotalwithAdjustment").val();
  7960. element.find(".hfRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(row.TotalRowAmount), 2));
  7961. if (element.hasClass('SplitItem'))
  7962. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalRowAmount, 2));
  7963. }
  7964. else {
  7965. element.find('.prodTotalPrice').text('');
  7966. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalRowAmount, 2));
  7967. }
  7968. }
  7969. if (row.TotalDiscount != 0 && row.TotalDiscount != undefined)
  7970. element.find('#inv_txtdiscount').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalDiscount, 2));
  7971. if (row.invoiceItemId != "0" && ($(".hdn_invoicetypeid").val() == "2")) {
  7972. var x = element.find('.hfRowTotalwithAdjustment');
  7973. element.find('.AdjustmentRow').click(function () {
  7974. InvoiceItem.Instance().editInvItemTaxAllocs(row.invoiceItemId, row.taxGroupId, row.itemId, row.orderItemId, element);
  7975. });
  7976. }
  7977. if (row.IsFoc == true) {
  7978. element.find('.delete').addClass('hidden');
  7979. element.find('.prodQuantity').prop('readonly', 'readonly');
  7980. element.find('.prodPrice').prop('readonly', 'readonly');
  7981. element.find("#inv_txtdiscount").prop('readonly', 'readonly');
  7982. element.find(".btnInvoice_DiscType").prop('disabled', true);
  7983. element.find('.prodQuantity').css('cursor', 'not-allowed');
  7984. element.find('.prodPrice').css('cursor', 'not-allowed');
  7985. element.find("#inv_txtdiscount").css('cursor', 'not-allowed');
  7986. }
  7987. }
  7988. else {
  7989. var element = $(".discount-addedrow:last");
  7990. if (row.inventoryTypeId == 5) {
  7991. element = $(".netdiscount-addedrow:last");
  7992. InvoiceItem.Instance().adddiscountrow(row, row.itemName, row.itemId, true);
  7993. }
  7994. if (row.inventoryTypeId == 6) {
  7995. InvoiceItem.Instance().adddiscountrow(row, row.itemName, row.itemId, false);
  7996. }
  7997. if (row.inventoryTypeId == 7) {
  7998. InvoiceItem.Instance().addExpenseRow(row, row.itemName, row.itemId, true);
  7999. }
  8000. }
  8001. }
  8002. loadTaxGroupAutoComplete(element) {
  8003. var txtTaxGroup = element.find(".prodTax");
  8004. var hfProdTax = element.find(".hfProdTax");
  8005. var hfAccount = element.find(".hf_Account");
  8006. var txtAccount = element.find(".txt_Account");
  8007. var accid = element.find(".hf_Account").val();
  8008. var taxgrpid = element.find(".hfProdTax").val();
  8009. var taxgrptext = element.find(".txtProdTax").val();
  8010. var acctext = element.find(".txt_AccountName").val();
  8011. var applytype = "Sales";
  8012. AutoCompleteHelper.getHelper().Create("#txt_prodTax_" + this.rowIndex, hfProdTax, _appsettings.server_url() + "/apis/v4/bizgaze/transact/tax/taxgroupautocomplete", function (result) {
  8013. if (hfProdTax.val() != '')
  8014. InvoiceItem.Instance().update_tax(element, hfProdTax.val());
  8015. });
  8016. var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/ledgers/ledgerautocomplete';
  8017. AutoCompleteHelper.getHelper().Create("#txt_Account_" + this.rowIndex, hfAccount, url, function (response) {
  8018. });
  8019. }
  8020. update_total() {
  8021. var totalAmount = 0;
  8022. var totalDiscountAmount = 0;
  8023. var totalNonDiscountedAmount = 0;
  8024. var totalTaxAmount = 0;
  8025. var totalTaxAdjustment = 0;
  8026. var totalAsseableAdjustment = 0;
  8027. var totalQty = 0;
  8028. var totalDiscountPercent = 0;
  8029. var totalDiscountValue = 0;
  8030. var totalAddlDiscountPercent = 0;
  8031. var totalAddlDiscountValue = 0;
  8032. var totalExpensePercent = 0;
  8033. var totalExpenseValue = 0;
  8034. var addexpenserow_total = 0;
  8035. $('.expense-row-total').each(function (i) {
  8036. var expense_row_total = Number($(this).html());
  8037. addexpenserow_total += expense_row_total;
  8038. });
  8039. var ConsumedWalletValue = 0;
  8040. var totalTaxPercent = 0;
  8041. var totalTaxValue = 0;
  8042. var totalCreditNote = 0;
  8043. var adddiscountrow_total = 0;
  8044. var netadddiscountrow_total = ConsumedWalletValue;
  8045. $('.discount-row-total').each(function (i) {
  8046. var discount_row_total = Number($(this).html());
  8047. adddiscountrow_total += discount_row_total;
  8048. });
  8049. $('.netdiscount-row-total').each(function (i) {
  8050. var discount_row_total = Number($(this).html());
  8051. netadddiscountrow_total += discount_row_total;
  8052. });
  8053. var itemdiscount_total = 0;
  8054. var totalLineAmount_total = 0;
  8055. $('.hfRowTotal').each(function (i) {
  8056. var element = $(this).parents(".item-row");
  8057. if (!element.hasClass('SplitItem')) {
  8058. var totalLineAmount = Number($(this).val());
  8059. if (!isNaN(totalLineAmount))
  8060. totalLineAmount_total += Number(totalLineAmount);
  8061. var discountPercent = 0;
  8062. var discountValue = 0;
  8063. var quantity = Number(element.find(".prodQuantity").val());
  8064. var unitPrice = Number(element.find(".prodPrice").val());
  8065. var exciseAmount = Number(element.find(".exciseAmount").val());
  8066. if (isNaN(exciseAmount))
  8067. exciseAmount = 0;
  8068. var nonexciseAmount = totalLineAmount - exciseAmount;
  8069. if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Val' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
  8070. discountValue = Number(element.find('.inv_txtaddldiscount').val());
  8071. }
  8072. else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == '%' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
  8073. discountPercent = Number(element.find('.inv_txtaddldiscount').val());
  8074. }
  8075. else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Mul') {
  8076. if (element.find('#hfProdDiscountList').val() != '' || element.find('#hfProdDiscountApplyTypes').val() != '') {
  8077. var discountsArray = element.find('#hfProdDiscountList').val().toString().split(',');
  8078. var applyTypes = element.find('#hfProdDiscountApplyTypes').val().toString().split(',');
  8079. var price = Number(unitPrice) * Number(quantity);
  8080. var currentAmount = Number(unitPrice) * Number(quantity);
  8081. $.each(discountsArray, function (j) {
  8082. var percent = discountsArray[j];
  8083. var applyType = applyTypes[j];
  8084. var discount = 0;
  8085. if (applyType == 'NET' || applyType == '1') {
  8086. discount = Number(price) * Number(percent) / 100;
  8087. currentAmount -= Number(discount);
  8088. }
  8089. else {
  8090. discount = Number(currentAmount) * Number(percent) / 100;
  8091. currentAmount -= Number(discount);
  8092. }
  8093. discountValue += Number(discount);
  8094. });
  8095. element.find('.inv_txtaddldiscount').val(discountValue);
  8096. }
  8097. else {
  8098. discountValue = Number(element.find('.inv_txtaddldiscount').val());
  8099. }
  8100. }
  8101. if (!isNaN(discountPercent))
  8102. totalDiscountPercent += Number(discountPercent);
  8103. if (!isNaN(discountValue))
  8104. totalAddlDiscountValue += Number(discountValue);
  8105. var discountAmount = 0;
  8106. discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
  8107. + (Number(quantity) * Number(discountValue));
  8108. if ($(".hdn_invoicetypeid").val() == "1" && (element.find(".hf_IsManualUOM").val() == "true" || element.find(".hf_IsMultipleUOM").val() == "true")) {
  8109. let ConversionQuantity = Number(element.find(".hf_ConversionQuantity").val());
  8110. if (ConversionQuantity > 0)
  8111. discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
  8112. + (Number(ConversionQuantity) * Number(discountValue));
  8113. }
  8114. discountAmount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discountAmount, 2));
  8115. itemdiscount_total += discountAmount;
  8116. var discountedAmount = Number(totalLineAmount) - Number(discountAmount);
  8117. totalDiscountAmount += Number(discountAmount);
  8118. element.find(".hfDiscountedAmount").val(discountAmount);
  8119. let invoiceid = $(".hdn_invoiceid").val();
  8120. if (invoiceid == undefined || invoiceid == "null")
  8121. invoiceid = 0;
  8122. if (($(".hdn_invoicetypeid").val() == "2") && invoiceid != 0) {
  8123. element.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2));
  8124. element.find(".prodTotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2).toString());
  8125. }
  8126. else
  8127. element.find(".prodTotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2).toString());
  8128. }
  8129. });
  8130. if (InvoiceItem.Instance().SplitedInvoiceItemList.length > 0) {
  8131. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  8132. var totalline_Amount = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
  8133. var discountAmount = 0;
  8134. var nonexciseAmount = totalline_Amount - Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount);
  8135. discountAmount = (Number(nonexciseAmount) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountPercent) / 100)
  8136. + (Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountValue));
  8137. discountAmount = Number(discountAmount);
  8138. totalLineAmount_total += Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
  8139. itemdiscount_total += discountAmount;
  8140. totalDiscountAmount += discountAmount;
  8141. }
  8142. }
  8143. var overalldiscountpercent = 0;
  8144. if (adddiscountrow_total != 0) {
  8145. overalldiscountpercent = (100 * Number(adddiscountrow_total)) / Number(totalLineAmount_total);
  8146. overalldiscountpercent = Number(overalldiscountpercent);
  8147. $("#hfOverallDiscountPercent").val(overalldiscountpercent);
  8148. }
  8149. var taxAmounts = [];
  8150. $('.hfRowTotal').each(function (i) {
  8151. var element = $(this).parents(".item-row");
  8152. if (!element.hasClass('SplitItem')) {
  8153. var totalLineAmount = Number($(this).val());
  8154. var quantity = element.find(".prodQuantity").val();
  8155. var UnitPrice = element.find(".prodPrice").val();
  8156. var Discount = element.find("#inv_txtdiscount").val();
  8157. var DiscountType = element.find(".btn_inv_DiscType").val();
  8158. discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
  8159. var assesableAmount = totalLineAmount - discountAmount;
  8160. assesableAmount = Number(assesableAmount);
  8161. if (element.find(".hf_IsMultipleUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
  8162. let ItemId = Number(element.find(".selectedItemId").val());
  8163. let SelectedUnitId = Number(element.find(".hf_AlternateUnitId").val());
  8164. if (SelectedUnitId == 0 || SelectedUnitId == 1) {
  8165. SelectedUnitId = Number(element.find(".ddl_MultipleUOMs").val());
  8166. }
  8167. if (SelectedUnitId != 0 && SelectedUnitId != 1) {
  8168. let Uom = InvoiceItem.Instance().UOMs.find(x => x.ItemId == ItemId);
  8169. let SelectedUOM = Uom.MultipleUOMs.find(x => x.SchemaDetailId == SelectedUnitId);
  8170. let DefaultSize = SelectedUOM.DefaultSize;
  8171. let AlternateSize = SelectedUOM.AlternateSize;
  8172. quantity = Number(element.find(".prodQuantity").val()) * (AlternateSize / DefaultSize);
  8173. totalLineAmount = Number(assesableAmount) * (AlternateSize / DefaultSize);
  8174. element.find(".prodTotalPrice").text(totalLineAmount);
  8175. element.find(".hfRowTotalwithAdjustment").val(totalLineAmount);
  8176. let Conversion = SelectedUOM.DefaultSize + " " + SelectedUOM.DefaultUnitName + " = " + SelectedUOM.AlternateSize + " " + SelectedUOM.AlternateUnitName;
  8177. element.find(".ItemConversion").text(Conversion);
  8178. element.find(".SelectedUOMName").text('(' + SelectedUOM.DefaultUnitName + ')');
  8179. let UOMCalc = UnitPrice + ' X ' + quantity + ' ( ' + SelectedUOM.AlternateUnitName + ' )';
  8180. if (Discount > 0) {
  8181. if (DiscountType == 'Val') {
  8182. UOMCalc = '(' + UnitPrice + ' - ' + Discount + ')' + ' X ' + quantity + ' ( ' + SelectedUOM.DefaultUnitName + ' )';
  8183. }
  8184. else if (DiscountType == '%') {
  8185. UOMCalc = '(' + UnitPrice + ' - ' + Discount + '%)' + ' X ' + quantity + ' ( ' + SelectedUOM.DefaultUnitName + ' )';
  8186. }
  8187. }
  8188. element.find(".UOMCalc").text(UOMCalc);
  8189. }
  8190. else {
  8191. element.find(".ItemConversion").text("");
  8192. element.find(".UOMCalc").text("");
  8193. element.find(".SelectedUOMName").text("");
  8194. }
  8195. }
  8196. if (element.find(".hf_IsManualUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
  8197. let ItemId = Number(element.find(".selectedItemId").val());
  8198. let SelectedUnitId = Number(element.find(".hf_AlternateUnitId").val());
  8199. let ConversionQuantity = Number(element.find(".hf_ConversionQuantity").val());
  8200. let AlternateUnitName = element.find(".hf_AlternateUnitName").val();
  8201. let ItemUnitName = element.find(".hf_UnitName").val();
  8202. totalLineAmount = Number(ConversionQuantity) * Number(UnitPrice);
  8203. discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
  8204. var assesableAmount = totalLineAmount - discountAmount;
  8205. assesableAmount = Number(assesableAmount);
  8206. totalLineAmount = assesableAmount;
  8207. if (SelectedUnitId != 0 && SelectedUnitId != 1) {
  8208. element.find(".prodTotalPrice").text(totalLineAmount);
  8209. element.find(".hfRowTotalwithAdjustment").val(totalLineAmount);
  8210. element.find(".SelectedUOMName").text('(' + ItemUnitName + ')');
  8211. let UOMCalc = UnitPrice + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
  8212. if (Discount > 0) {
  8213. if (DiscountType == 'Val') {
  8214. UOMCalc = '(' + UnitPrice + ' - ' + Discount + ')' + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
  8215. }
  8216. else if (DiscountType == '%') {
  8217. UOMCalc = '(' + UnitPrice + ' - ' + Discount + '%)' + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
  8218. }
  8219. }
  8220. element.find(".UOMCalc").text(UOMCalc);
  8221. }
  8222. else {
  8223. element.find(".ItemConversion").text("");
  8224. element.find(".UOMCalc").text("");
  8225. element.find(".SelectedUOMName").text("");
  8226. }
  8227. }
  8228. if (!isNaN(totalLineAmount))
  8229. totalNonDiscountedAmount += Number(totalLineAmount);
  8230. discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
  8231. var assesableAmount = totalLineAmount - discountAmount;
  8232. var taxPercents = element.find(".hfProdTaxPercent").val();
  8233. if (taxPercents != undefined)
  8234. var taxpercentarray = taxPercents.toString().split(',');
  8235. var taxValue = 0;
  8236. var assesableAdjustment = Number(element.find('.hfItemAssesableAdjustmentVal').val());
  8237. var taxAdjustment = Number(element.find('.hfItemTaxAdjsutmentVal').val());
  8238. if (!isNaN(taxAdjustment))
  8239. totalTaxAdjustment += Number(taxAdjustment);
  8240. if (!isNaN(assesableAdjustment))
  8241. totalAsseableAdjustment += Number(assesableAdjustment);
  8242. var cumlTax = 0;
  8243. var cumtaxtotal = 0;
  8244. if ($(".dropdown_istaxinclusive").val() == "true") {
  8245. for (var i = 0; i < taxpercentarray.length; i++) {
  8246. var taxPercentModel1 = taxpercentarray[i];
  8247. var taxPercentM1 = taxPercentModel1.split(":");
  8248. if (!isNaN(Number(taxPercentM1[1])))
  8249. cumlTax += Number(taxPercentM1[1]);
  8250. }
  8251. var currentAmt = Number((Number(assesableAmount) * 100) / (100 + Number(cumlTax)));
  8252. cumtaxtotal = (Number(assesableAmount) - Number(currentAmt));
  8253. }
  8254. if (taxpercentarray != undefined) {
  8255. for (var i = 0; i < taxpercentarray.length; i++) {
  8256. var taxPercentModel = taxpercentarray[i];
  8257. var taxPercentM = taxPercentModel.split(":");
  8258. var ledgerid = taxPercentM[0];
  8259. var taxPercent = Number(taxPercentM[1]);
  8260. let taxAmt = 0;
  8261. if ($(".dropdown_istaxinclusive").val() == "true") {
  8262. taxAmt = Number((taxPercent * cumtaxtotal) / cumlTax);
  8263. }
  8264. else {
  8265. var tax = (Number(assesableAmount) * Number(taxPercent) / 100);
  8266. taxAmt = Number(tax);
  8267. }
  8268. var ledgerexists = false;
  8269. $.map(taxAmounts, function (e, i) {
  8270. if (e.LedgerId == ledgerid) {
  8271. ledgerexists = true;
  8272. taxAmounts[i].TaxAmount = Number(taxAmounts[i].TaxAmount) + Number(taxAmt);
  8273. }
  8274. });
  8275. if (!ledgerexists) {
  8276. taxAmounts.push({
  8277. LedgerId: ledgerid,
  8278. TaxAmount: taxAmt,
  8279. });
  8280. }
  8281. }
  8282. }
  8283. totalAmount += Number(totalLineAmount);
  8284. totalQty += Number(quantity);
  8285. }
  8286. });
  8287. if (InvoiceItem.Instance().SplitedInvoiceItemList.length > 0) {
  8288. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  8289. var TotalLineAmount = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
  8290. var quantiy = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity);
  8291. if (!isNaN(TotalLineAmount))
  8292. totalNonDiscountedAmount += Number(TotalLineAmount);
  8293. var discountAmount = (quantiy * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountValue)) + ((Number(TotalLineAmount) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountPercent)) / 100) + (Number(TotalLineAmount) * Number(overalldiscountpercent) / 100);
  8294. ;
  8295. var assesableAmount = TotalLineAmount - discountAmount;
  8296. assesableAmount = Number(assesableAmount);
  8297. var taxPercents = '';
  8298. var instance = this;
  8299. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent == undefined || InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent == 0) {
  8300. var element = "";
  8301. $(".SplitItem").each(function () {
  8302. if ($(this).find(".selectedItemId").val() == InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId) {
  8303. element = $(this);
  8304. taxPercents = element.find('.hfProdTaxPercent').val();
  8305. }
  8306. });
  8307. }
  8308. else
  8309. taxPercents = InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent;
  8310. if (taxPercents != undefined && taxPercents != '')
  8311. var taxpercentarray = taxPercents.split(',');
  8312. var assesableAdjustment = InvoiceItem.Instance().SplitedInvoiceItemList[i].assesableAdjustment;
  8313. var taxAdjustment = InvoiceItem.Instance().SplitedInvoiceItemList[i].taxAdjustment;
  8314. if (!isNaN(taxAdjustment))
  8315. totalTaxAdjustment += Number(taxAdjustment);
  8316. if (!isNaN(assesableAdjustment))
  8317. totalAsseableAdjustment += Number(assesableAdjustment);
  8318. var cumlTax = 0;
  8319. var cumtaxtotal = 0;
  8320. if ($(".dropdown_istaxinclusive").val() == "true") {
  8321. for (var j = 0; j < taxpercentarray.length; j++) {
  8322. var taxPercentModel1 = taxpercentarray[j];
  8323. var taxPercentM1 = taxPercentModel1.split(":");
  8324. if (!isNaN(taxPercentM1[1]))
  8325. cumlTax += Number(taxPercentM1[1]);
  8326. }
  8327. var currentAmt = Number((Number(assesableAmount) * 100) / (100 + Number(cumlTax)));
  8328. cumtaxtotal = (Number(assesableAmount) - Number(currentAmt));
  8329. }
  8330. if (taxpercentarray != undefined) {
  8331. for (var k = 0; k < taxpercentarray.length; k++) {
  8332. if (taxpercentarray[k] != '' && taxpercentarray[k] != null) {
  8333. var taxPercentModel = taxpercentarray[k];
  8334. var taxPercentM = taxPercentModel.split(":");
  8335. var ledgerid = taxPercentM[0];
  8336. var taxPercent = taxPercentM[1];
  8337. var taxAmt = 0;
  8338. if ($(".dropdown_istaxinclusive").val() == "true") {
  8339. taxAmt = Number((taxPercent * cumtaxtotal) / cumlTax);
  8340. }
  8341. else {
  8342. var tax = (Number(assesableAmount) * Number(taxPercent) / 100);
  8343. taxAmt = Number(tax);
  8344. }
  8345. var ledgerexists = false;
  8346. $.map(taxAmounts, function (e, m) {
  8347. if (e.LedgerId == ledgerid) {
  8348. ledgerexists = true;
  8349. taxAmounts[m].TaxAmount = Number(taxAmounts[m].TaxAmount) + Number(taxAmt);
  8350. }
  8351. });
  8352. if (!ledgerexists) {
  8353. taxAmounts.push({
  8354. LedgerId: ledgerid,
  8355. TaxAmount: taxAmt,
  8356. });
  8357. }
  8358. }
  8359. }
  8360. }
  8361. totalAmount += Number(TotalLineAmount);
  8362. totalQty += Number(quantiy);
  8363. }
  8364. }
  8365. var taxAmount = 0;
  8366. var taxAdjustment = 0;
  8367. for (var i = 0; i < taxAmounts.length; i++) {
  8368. if (!isNaN(taxAmounts[i].TaxAmount)) {
  8369. var taxamt = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(taxAmounts[i].TaxAmount, 2);
  8370. taxAmount += Number(taxamt);
  8371. }
  8372. }
  8373. if (!isNaN(totalTaxAdjustment))
  8374. totalTaxAdjustment = totalTaxAdjustment;
  8375. if (!isNaN(totalAsseableAdjustment)) {
  8376. totalAsseableAdjustment = totalAsseableAdjustment;
  8377. }
  8378. else {
  8379. totalAsseableAdjustment = 0;
  8380. }
  8381. if (!isNaN(totalAsseableAdjustment))
  8382. totalAmount += Number(totalAsseableAdjustment);
  8383. totalTaxAmount = Number(taxAmount) + Number(totalTaxAdjustment);
  8384. totalDiscountAmount += adddiscountrow_total;
  8385. var totaltax = totalTaxAmount;
  8386. var grosstotal = totalAmount;
  8387. var creditnotes = 0;
  8388. var assessableadjustment = 0;
  8389. if (!isNaN(Number($("#txt_assessableadjustment").val())))
  8390. assessableadjustment = Number($("#txt_assessableadjustment").val());
  8391. var subtotal = grosstotal - totalDiscountAmount + assessableadjustment;
  8392. let itemCount = $("#" + Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId()).find(".InvoiceItems .item-addedrow .selectedItemId[value!='0']").length;
  8393. $("#" + Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId()).find("#Item_Count").text(itemCount);
  8394. var overalldiscount = 0;
  8395. var taxadjustment = 0;
  8396. if (!isNaN(Number($('#txt_taxadjustment').val()))) {
  8397. taxadjustment = Number($('#txt_taxadjustment').val());
  8398. }
  8399. totaltax = Number(totaltax) + Number(taxadjustment);
  8400. totaltax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaltax, 2);
  8401. $('#totalTax').html(totaltax);
  8402. $('.hdn_taxamount').val(totaltax);
  8403. $('#grosstotal').html(grosstotal);
  8404. $('#totalItemDiscount').html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(itemdiscount_total, 2));
  8405. $('#totalDiscount').html(totalDiscountAmount);
  8406. $("#totalinvoiceqty").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalQty, 2));
  8407. var expense = 0;
  8408. if (!isNaN(Number($('#txtOverallExpenseAmount').val()))) {
  8409. expense = Number($('#txtOverallExpenseAmount').val());
  8410. $("#totalexpense").text(expense);
  8411. }
  8412. var adjustment = 0;
  8413. var nettotal = Number(subtotal) + Number(addexpenserow_total) - Number(overalldiscount) - Number(netadddiscountrow_total) + Number(adjustment);
  8414. if ($(".dropdown_istaxinclusive").val() == "false")
  8415. nettotal += Number(totaltax);
  8416. if ($(".dropdown_istaxinclusive").val() == "true") {
  8417. subtotal = Number(subtotal) - Number(totalTaxAmount);
  8418. }
  8419. subtotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(subtotal, 2);
  8420. $('#subtotal').html(subtotal);
  8421. $('.hdn_assessableamount').val(subtotal);
  8422. $('.hdn_assessableamount').val($('#subtotal').text());
  8423. if ($("#hf_AdjustmentAccountId").val() != undefined) {
  8424. $(".hdn_adjustmentaccountId").val($("#hf_AdjustmentAccountId").val());
  8425. }
  8426. if ($("#chk_tcsapplied").val() != undefined) {
  8427. if ($("#chk_tcsapplied").prop("checked")) {
  8428. let tcstax = 0;
  8429. let tcsrate = 0;
  8430. tcsrate = InvoiceItem.Instance().TaxRate;
  8431. if (tcsrate != 0) {
  8432. tcstax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(subtotal) + Number(totalTaxAmount)) * (tcsrate / 100), 2);
  8433. $('.number_tcsamount').val(tcstax);
  8434. nettotal += Number(tcstax);
  8435. $('#lbltcsrate').text("TCS " + tcsrate + " %");
  8436. var tcsadjustment = 0;
  8437. if (!isNaN(Number($('.txt_tcsadjustment').val()))) {
  8438. tcsadjustment = Number($('.txt_tcsadjustment').val());
  8439. }
  8440. $(".number_tcstaxrate").val(tcsrate);
  8441. $('.number_tcsamount').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(tcstax) + tcsadjustment), 2));
  8442. nettotal += tcsadjustment;
  8443. }
  8444. }
  8445. else {
  8446. $('.txt_tcsadjustment').val(0);
  8447. $('.number_tcsamount').val(0);
  8448. }
  8449. }
  8450. if ($("#chk_tdsapplied").val() != undefined) {
  8451. if ($("#chk_tdsapplied").prop("checked")) {
  8452. let taxcodeid = $(".txtAutoComplete_tdstaxcodeid").val();
  8453. let tdsrate = $(".number_tdstaxrate").val();
  8454. let tdstax = 0;
  8455. if (tdsrate != 0) {
  8456. tdstax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(subtotal) * (Number(tdsrate) / 100), 2);
  8457. $('.number_tdsamount').val(tdstax);
  8458. }
  8459. nettotal -= Number(tdstax);
  8460. }
  8461. else {
  8462. $('.txt_tdsadjustment').val(0);
  8463. $('.number_tdsamount').val(0);
  8464. }
  8465. }
  8466. $('.nettotal').html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(nettotal, 2));
  8467. }
  8468. loadItemAutoComplete(element) {
  8469. let userinfo = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
  8470. let sessionid = userinfo.sessionId;
  8471. let postData = null;
  8472. element.find(".prodName").select2({
  8473. placeholder: "Select",
  8474. tags: false,
  8475. allowClear: true,
  8476. theme: "default select2ErrorClass",
  8477. data: [],
  8478. ajax: {
  8479. url: function (request) {
  8480. let reqUrl = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/getitemsdcitemsandinvoiceitems';
  8481. return reqUrl;
  8482. },
  8483. type: "POST",
  8484. contentType: 'application/json',
  8485. dataType: 'json',
  8486. data: function (params) {
  8487. let Term = params.term;
  8488. sessionid = sessionid.replace('#', '');
  8489. postData = {
  8490. LobId: Number($(".hfAutoCompleteId_lobid").val()),
  8491. ItemIds: InvoiceItem.instance.itemIds,
  8492. term: Term,
  8493. };
  8494. return JSON.stringify(postData);
  8495. },
  8496. beforeSend: function (xhr) {
  8497. if (userinfo !== undefined && userinfo !== null) {
  8498. xhr.setRequestHeader("Authorization", "Basic " + userinfo.sessionId);
  8499. xhr.setRequestHeader('geoposition', userinfo.latd + ':' + userinfo.lgId);
  8500. }
  8501. },
  8502. processResults: function (data) {
  8503. return {
  8504. results: jQuery.map(JSON.parse(data.result), function (item) {
  8505. return {
  8506. id: item.Value,
  8507. text: item.SelectText,
  8508. addlInfo: item.addlData
  8509. };
  8510. })
  8511. };
  8512. },
  8513. },
  8514. });
  8515. }
  8516. itemChange(element, id, hdnAutoId) {
  8517. id = element.find(".prodName option:selected").val();
  8518. element.find(".prodName").change(function () {
  8519. if (id == null || id == 0) {
  8520. id = element.find(".prodName option:selected").val();
  8521. }
  8522. id = element.find(".prodName option:selected").val();
  8523. if (id != 0) {
  8524. var hdnItemId = id;
  8525. element.find(".selectedItemId").val(id);
  8526. if (id.search(':') == -1)
  8527. hdnItemId = id;
  8528. else
  8529. hdnItemId = id.split(':')[1];
  8530. if (element.find(".hfoldItemId").val() != hdnItemId) {
  8531. if (element.find(".orderItemId").val() == "0" && hdnItemId != "") {
  8532. if (element.find(".hfoldItemId").val() != "0" && element.find(".hfoldItemId").val() != undefined && element.find(".hfoldItemId").val() != "") {
  8533. let index = InvoiceItem.Instance().itemIds.indexOf(Number(element.find(".hfoldItemId").val()), 0);
  8534. if (index > -1) {
  8535. InvoiceItem.Instance().itemIds.splice(index, 1);
  8536. }
  8537. }
  8538. InvoiceItem.Instance().itemIds.push(Number(hdnItemId));
  8539. }
  8540. var x = [];
  8541. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  8542. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == element.find(".hfoldItemId").val()) {
  8543. x.push(i);
  8544. }
  8545. }
  8546. for (var i = x.length - 1; i >= 0; i--) {
  8547. InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
  8548. }
  8549. $('.item-row').each(function () {
  8550. if ($(this).find('.hfOfferedItemId').val() == element.find(".hfoldItemId").val())
  8551. $(this).remove();
  8552. });
  8553. element.find(".hfoldItemId").val(hdnItemId);
  8554. element.find(".div_UnitPrice").removeClass('hidden');
  8555. element.find(".div_SplitInvoiceItem").addClass("hidden");
  8556. element.find(".prodQuantity").val(0);
  8557. element.find(".prodPrice").val(0);
  8558. element.find(".prodQuantity").prop('disabled', false);
  8559. element.find('.prodQuantity').css('cursor', 'default');
  8560. element.find('.prodPrice').css('cursor', 'default');
  8561. element.find("#inv_txtdiscount").css('cursor', 'default');
  8562. element.find('#inv_txtdiscount').prop('disabled', false);
  8563. element.find('#inv_txtdiscount').val(0);
  8564. element.find('.btn_inv_DiscType').removeClass('hidden');
  8565. element.find(".btn_inv_DiscType").prop('disabled', false);
  8566. element.find(".prodTax").empty();
  8567. element.find(".txt_Account").empty();
  8568. if (element.hasClass('SplitItem')) {
  8569. element.find(".spn_InvoiceItem").unbind("click", null);
  8570. }
  8571. element.find(".hfRowTotalwithAdjustment").val("0");
  8572. element.find('.prodTotalPrice').text('0');
  8573. $("#txt_Adjustment").val("0");
  8574. InvoiceItem.Instance().update_total();
  8575. InvoiceItem.Instance().TotalAdjustment();
  8576. element.removeClass('SplitItem');
  8577. element.find(".hfMrpId").val(0);
  8578. }
  8579. if ($(hdnAutoId).val().toString().search(':') == -1)
  8580. element.find(".hfoldItemId").val($(hdnAutoId).val());
  8581. else
  8582. element.find(".hfoldItemId").val($(hdnAutoId).val().toString().split(':')[1]);
  8583. var hdnSelectedItemIdVal = 0;
  8584. hdnSelectedItemIdVal = id;
  8585. if (id != 0) {
  8586. id = id;
  8587. var hdnOrderItemIdVal = 0;
  8588. var hdnDcItemIdVal = 0;
  8589. var ids = $(hdnAutoId).val();
  8590. if (ids.toString().search(':') == -1) {
  8591. hdnSelectedItemIdVal = Number($(hdnAutoId).val());
  8592. }
  8593. else {
  8594. var selectedVal = hdnAutoId;
  8595. if (!InvoiceItem.Instance().AutoDc) {
  8596. hdnOrderItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
  8597. if (InvoiceItem.Instance().orderid != 0 && InvoiceItem.Instance().OrderSettingId == 2)
  8598. hdnOrderItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
  8599. else {
  8600. hdnDcItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
  8601. element.find(".dcItemId").val(hdnDcItemIdVal);
  8602. let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(hdnDcItemIdVal, 0);
  8603. if (dcindex == -1)
  8604. InvoiceItem.Instance().dcItemIds.push(hdnDcItemIdVal);
  8605. }
  8606. }
  8607. hdnSelectedItemIdVal = Number($(selectedVal).val().toString().split(':')[1]);
  8608. }
  8609. var item = element.find(".prodName").text();
  8610. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemById(hdnSelectedItemIdVal).then(function (response) {
  8611. var inventarytype = response.result.InventoryTypeId;
  8612. if (inventarytype == 5 || inventarytype == 6) {
  8613. InvoiceItem.Instance().addDiscountRow(element, item, id);
  8614. var elementfordisc = $(".discount-row:last");
  8615. InvoiceItem.Instance().loadItemRowDetails(elementfordisc, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
  8616. }
  8617. else if (inventarytype == 7) {
  8618. InvoiceItem.Instance().addExpenseRow(element, item, id, true);
  8619. var elementforexp = $(".expense-row:last");
  8620. InvoiceItem.Instance().loadItemRowDetails(elementforexp, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
  8621. }
  8622. else {
  8623. var itemid = 0;
  8624. if (hdnSelectedItemIdVal == undefined) {
  8625. InvoiceItem.Instance().loadItemRowDetails(element, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
  8626. }
  8627. else {
  8628. InvoiceItem.Instance().loadItemRowDetails(element, hdnOrderItemIdVal, hdnDcItemIdVal, hdnSelectedItemIdVal);
  8629. }
  8630. }
  8631. });
  8632. }
  8633. }
  8634. });
  8635. }
  8636. itemsAutoComplete(element) {
  8637. var txtAutoSearchCtrl = element.find(".prodName");
  8638. var hdnOrderItemId = element.find(".orderItemId");
  8639. var hdnDcItemId = element.find(".dcItemId");
  8640. var hdnSelectedItemId = element.find(".selectedItemId");
  8641. let lobid = $(".hfAutoCompleteId_lobid").val();
  8642. if ((hdnSelectedItemId).val() != 0 && (hdnSelectedItemId).val() != "") {
  8643. this.itemIds.push(Number((hdnSelectedItemId).val()));
  8644. element.find(".hfoldItemId").val((hdnSelectedItemId).val());
  8645. }
  8646. let hdnAutoId = hdnSelectedItemId;
  8647. let orderid = InvoiceItem.Instance().orderid;
  8648. let dcid = InvoiceItem.Instance().dcid;
  8649. let invoiceid = $(".hdn_invoiceid").val();
  8650. if (invoiceid == undefined || invoiceid == "null")
  8651. invoiceid = 0;
  8652. var url = "";
  8653. var id = 0;
  8654. if ((orderid == 0) && (InvoiceItem.Instance().AutoDc) && InvoiceItem.Instance().OrderSettingId == 0 && ($('#hfInv_IsRetun').val() != "1" && ($(".hdn_refinvoiceid").val() == undefined || $(".hdn_refinvoiceid").val() == 0))) {
  8655. InvoiceItem.instance.loadItemAutoComplete(element);
  8656. }
  8657. else {
  8658. if ((orderid == 0) && (dcid != 0 && InvoiceItem.Instance().AutoDc == false))
  8659. url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autodcitemforinvoicewithoutorder/dcid/" + dcid + "/itemids/" + InvoiceItem.Instance().itemIds;
  8660. else if (InvoiceItem.Instance().OrderSettingId == 1)
  8661. url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autodcitemforinvoice/dcid/" + dcid + "/itemids/" + InvoiceItem.Instance().dcItemIds;
  8662. else
  8663. url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autopendingorderitemforinvoice/orderid/" + orderid + "/itemids/" + InvoiceItem.Instance().itemIds;
  8664. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && ($('#hfInv_IsRetun').val() == "1" || ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0))) {
  8665. var refinvoiceid = 0;
  8666. if ($('#hfInv_IsRetun').val() == "1") {
  8667. refinvoiceid = Number(invoiceid);
  8668. $(".hdn_refinvoiceid").val(refinvoiceid);
  8669. }
  8670. if ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0)
  8671. refinvoiceid = Number($(".hdn_refinvoiceid").val());
  8672. url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autopendingreturnitemforinvoice/invoiceid/" + refinvoiceid + "/itemids/" + InvoiceItem.Instance().itemIds;
  8673. }
  8674. AutoCompleteHelper.getHelper().Create(txtAutoSearchCtrl, hdnAutoId, url, function (result) {
  8675. InvoiceItem.instance.itemChange(element, result.id, hdnAutoId);
  8676. });
  8677. }
  8678. InvoiceItem.Instance().loadItemRowDetails(element, hdnOrderItemId.val(), hdnDcItemId.val(), $(hdnSelectedItemId).val());
  8679. }
  8680. addDiscountRow(element, txtAutoSearchCtrl, hdnAutoId) {
  8681. InvoiceItem.Instance().RemoveItem(element);
  8682. InvoiceItem.Instance().adddiscountrow(null, txtAutoSearchCtrl, hdnAutoId, false);
  8683. }
  8684. adddiscountrow(row, txtAutoSearchCtrl, hdnAutoId, applyOnNet) {
  8685. let isemptyrow = false;
  8686. $(".addednetdiscount-row").each(function () {
  8687. if ($(this).find(".txtDiscountName").val() == undefined || $(this).find(".txtDiscountName").val() == null) {
  8688. isemptyrow = true;
  8689. }
  8690. });
  8691. if (isemptyrow) {
  8692. MessageHelper.Instance().showError("Please Select Coupon Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  8693. return false;
  8694. }
  8695. var discountid = 0;
  8696. var discountname = '';
  8697. var description = '';
  8698. var ledgerId = 0;
  8699. var rowname = "discount-row";
  8700. var percent = 0.0;
  8701. var value = 0.0;
  8702. var invoicechargeid = 0;
  8703. var appliedWhole = false;
  8704. var inventorytypeid = 6;
  8705. var readonly = "";
  8706. if (applyOnNet) {
  8707. rowname = "netdiscount-row";
  8708. appliedWhole = true;
  8709. inventorytypeid = 5;
  8710. }
  8711. if ($("#hfDirectInvoice").val() == "0")
  8712. invoicechargeid = 0;
  8713. var html = '<div class="' + rowname + ' added' + rowname + ' row mb-2 mx-0" ' + readonly + '>' +
  8714. '<div class="discount-name col-sm-4">' +
  8715. '<div class="floating-label-form-group min-padding" style="margin-left:20px;border-bottom:0px"><input type="hidden" class="selectedInvoiceChargeId" value="' + invoicechargeid + '" />';
  8716. if (row != null) {
  8717. if (row.addlDiscountPercent != "") {
  8718. percent = row.addlDiscountPercent;
  8719. }
  8720. if (row.addlDiscountValue != "") {
  8721. value = row.addlDiscountValue;
  8722. }
  8723. if (row.description != "" && row.description != null) {
  8724. description = row.description;
  8725. }
  8726. html += '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  8727. '<input type="hidden" class="orderItemId" value="' + row.orderItemId + '" />' +
  8728. '<input type="hidden" class="dcItemId" value="' + row.dcItemId + '" />' +
  8729. '<input type="hidden" class="selectedInvoiceItemId" value="' + row.invoiceItemId + '" />' +
  8730. '<input type="hidden" class="refInvoiceItemId" value="' + row.RefInvoiceItemId + '" />' +
  8731. '<input type="hidden" class="selectedItemId" value="' + row.itemId + '" />' +
  8732. '<input type="hidden" class="inventorytypeid" value="' + row.itemId + '" />' +
  8733. '<input type="hidden" class="selectedItemName" value="' + row.itemname + '" />' +
  8734. '<input type="hidden" class="hfMrpId" value="' + row.MrpId + '" />' +
  8735. '<input type="hidden" class="offerapplied" value="0" />' +
  8736. '<input type="hidden" class="refNo" value="' + row.refNo + '" />' +
  8737. '<input type="hidden" class="description" value="' + row.description + '" />' +
  8738. '<input type="hidden" class="IsExchangeItem" value="' + row.ExchangeItem + '" />' +
  8739. '<input type="hidden" class="maxQty" value="' + row.maxQty + '" />' +
  8740. '<input type="hidden" class="hf_Account" value="' + row.accountId + '" />' +
  8741. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="' + row.taxAdjustment + '" />' +
  8742. '<input type="hidden" class="hfProdTax" value="' + row.taxGroupId + '" />' +
  8743. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="' + row.assesableAdjustment + '" />' +
  8744. '<input type="hidden" class="prodPrice text-center form-control" placeholder="0.00" value="0" />';
  8745. }
  8746. else {
  8747. html += '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  8748. '<input type="hidden" class="orderItemId" value="0" />' +
  8749. '<input type="hidden" class="dcItemId" value="0" />' +
  8750. '<input type="hidden" class="selectedInvoiceItemId" value="0" />' +
  8751. '<input type="hidden" class="selectedItemName" value="" />' +
  8752. '<input type="hidden" class="refInvoiceItemId" value="0" />' +
  8753. '<input type="hidden" class="selectedItemId" value="0" />' +
  8754. '<input type="hidden" class="inventorytypeid" value="0" />' +
  8755. '<input type="hidden" class="hfMrpId" value="0" />' +
  8756. '<input type="hidden" class="offerapplied" value="0" />' +
  8757. '<input type="hidden" class="refNo" value="0" />' +
  8758. '<input type="hidden" class="description" value="0" />' +
  8759. '<input type="hidden" class="IsExchangeItem" value="0" />' +
  8760. '<input type="hidden" class="maxQty" value="0" />' +
  8761. '<input type="hidden" class="hf_Account" value="0" />' +
  8762. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="0" />' +
  8763. '<input type="hidden" class="hfProdTax" value="0" />' +
  8764. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="0" />' +
  8765. '<input type="hidden" class="prodPrice text-center form-control" placeholder="0.00" value="0" />';
  8766. }
  8767. html += '<div class="input-group">' +
  8768. '<input type="hidden" class="hdnChargeTypeId" value="2" />' +
  8769. '<input type="hidden" class="hdnChargeLedgerId" value="' + ledgerId + '" />' +
  8770. '<a class="input-group-addon no-border bg-white delete" href="javascript:;" title="Remove row"><i class="fa fa-trash-o fa-lg mt-15 mr-2" style="margin-left:-25px;color:red"></i></a>';
  8771. if (rowname == "netdiscount-row") {
  8772. html += '<select type="text" class="txtDiscountName ui-autocomplete form-control text-control readonly' + readonly + '" placeholder=" Discount name" value="' + discountname + '" style="width:100%;"></select>';
  8773. }
  8774. else {
  8775. html += '<select type="text" class="txtDiscountName ui-autocomplete form-control readonly" placeholder=" Discount name" value="' + discountname + '" style="width:100%;"></select>';
  8776. }
  8777. html += '<input type="hidden" class="hfSelectedChargeId" value="' + discountid + '" />' +
  8778. '</div>' +
  8779. '</div></div>' +
  8780. '<div class="col-sm-4">' +
  8781. '<div class="floating-label-form-group min-padding"><input type="text" class="discountDesc form-control" placeholder="Description" value="' + description + '" /></div></div>' +
  8782. '<div class="col-sm-1">' +
  8783. '<div class="floating-label-form-group min-padding"><input type="text" class="percentage text-center form-control" placeholder="%" value="' + percent + '" /></div></div>' +
  8784. '<div class="col-sm-1">' +
  8785. '<div class="floating-label-form-group min-padding"><input type="text" class="fixedvalue text-center form-control" placeholder="0.00" value="' + value + '" /></div></div>' +
  8786. '<div class="col-sm-2 mt-10"><p class="pull-right"><span class="' + rowname + '-total control-label mt-5">0</span></p></div>' +
  8787. '</div>';
  8788. $("." + rowname + ":last").after(html);
  8789. var element = $("." + rowname + ":last");
  8790. InvoiceItem.Instance().bind(element, inventorytypeid);
  8791. if (inventorytypeid == 5)
  8792. InvoiceItem.Instance().GetOnInvoiceDiscountItem(element);
  8793. var txtChargeCode = element.find(".txtDiscountName");
  8794. var hfSelectedChargeId = element.find(".hfSelectedChargeId");
  8795. $(hfSelectedChargeId).val(hdnAutoId);
  8796. if (hdnAutoId != 0) {
  8797. var selecteditem = new Option(txtAutoSearchCtrl, hdnAutoId, true);
  8798. txtChargeCode.append(selecteditem);
  8799. }
  8800. if (rowname == "netdiscount-row" || rowname == "discount-row") {
  8801. var id = 0;
  8802. if (row != null) {
  8803. var selecteditem = new Option(row.itemName, row.itemId, true);
  8804. txtChargeCode.append(selecteditem);
  8805. }
  8806. let typeid = "7";
  8807. if (rowname == "discount-row") {
  8808. typeid = "5,6";
  8809. }
  8810. var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/itemautocompletebyinventorytype/inventorytypeid/' + Number(inventorytypeid) + '/lobid/' + $(".hfAutoCompleteId_lobid").val() + '/invoicetypeid/' + $('.hdn_invoicetypeid').val();
  8811. AutoCompleteHelper.getHelper().Create(txtChargeCode, hfSelectedChargeId, url, function (result) {
  8812. if (id != result.id) {
  8813. id = result.id;
  8814. var elementfordisc = $(".netdiscount-row:last");
  8815. var hdnOrderItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[0];
  8816. var hdnSelectedItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[1];
  8817. if (result.addlData != undefined && result.addlData != null) {
  8818. var defaultpercent = Number(result.addlData.split(':')[0]);
  8819. var defaultvalue = Number(result.addlData.split(':')[1]);
  8820. element.find('.percentage').val(defaultpercent);
  8821. element.find('.fixedvalue').val(defaultvalue);
  8822. }
  8823. InvoiceItem.Instance().loadItemRowDetails(element, 0, 0, hdnOrderItemIdVal);
  8824. }
  8825. });
  8826. }
  8827. $('.percentage').keypress(function (event) {
  8828. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  8829. }
  8830. else {
  8831. event.preventDefault();
  8832. }
  8833. }).on('paste', function (event) {
  8834. event.preventDefault();
  8835. });
  8836. $('.fixedvalue').keypress(function (event) {
  8837. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  8838. }
  8839. else {
  8840. event.preventDefault();
  8841. }
  8842. }).on('paste', function (event) {
  8843. event.preventDefault();
  8844. });
  8845. }
  8846. addExpenseRow(row, txtAutoSearchCtrl, hdnAutoId, applyOnNet) {
  8847. let isemptyrow = false;
  8848. $(".addedexpense-row").each(function () {
  8849. if ($(this).find(".txtExpenseName").val() == undefined || $(this).find(".txtExpenseName").val() == null) {
  8850. isemptyrow = true;
  8851. }
  8852. });
  8853. if (isemptyrow) {
  8854. MessageHelper.Instance().showError("Please Select Expense Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  8855. return false;
  8856. }
  8857. var discountid = 0;
  8858. var discountname = '';
  8859. var description = '';
  8860. var ledgerId = 0;
  8861. var rowname = "expense-row";
  8862. var percent = 0.0;
  8863. var value = 0.0;
  8864. var invoicechargeid = 0;
  8865. var appliedWhole = true;
  8866. var inventorytypeid = 7;
  8867. if ($("#hfDirectInvoice").val() == "0")
  8868. invoicechargeid = 0;
  8869. var html = '<div class="' + rowname + ' added' + rowname + ' row mb-2" >' +
  8870. '<div class="expense-name col-sm-4">' +
  8871. '<div class="floating-label-form-group min-padding" style="margin-left:20px;border-bottom:0px"><input type="hidden" class="selectedInvoiceChargeId" value="' + invoicechargeid + '" />';
  8872. if (row != null) {
  8873. if (row.addlDiscountPercent != "") {
  8874. percent = -row.addlDiscountPercent;
  8875. }
  8876. if (row.addlDiscountValue != "") {
  8877. value = -row.addlDiscountValue;
  8878. }
  8879. if (row.description != "") {
  8880. description = row.description;
  8881. }
  8882. html += '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  8883. '<input type="hidden" class="orderItemId" value="' + row.orderItemId + '" />' +
  8884. '<input type="hidden" class="dcItemId" value="' + row.dcItemId + '" />' +
  8885. '<input type="hidden" class="selectedInvoiceItemId" value="' + row.invoiceItemId + '" />' +
  8886. '<input type="hidden" class="refInvoiceItemId" value="' + row.RefInvoiceItemId + '" />' +
  8887. '<input type="hidden" class="selectedItemId" value="' + row.itemId + '" />' +
  8888. '<input type="hidden" class="inventorytypeid" value="' + row.itemId + '" />' +
  8889. '<input type="hidden" class="selectedItemName" value="' + row.itemname + '" />' +
  8890. '<input type="hidden" class="hfMrpId" value="' + row.MrpId + '" />' +
  8891. '<input type="hidden" class="offerapplied" value="0" />' +
  8892. '<input type="hidden" class="refNo" value="' + row.refNo + '" />' +
  8893. '<input type="hidden" class="description" value="' + row.description + '" />' +
  8894. '<input type="hidden" class="IsExchangeItem" value="' + row.ExchangeItem + '" />' +
  8895. '<input type="hidden" class="maxQty" value="' + row.maxQty + '" />' +
  8896. '<input type="hidden" class="hf_Account" value="' + row.accountId + '" />' +
  8897. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="' + row.taxAdjustment + '" />' +
  8898. '<input type="hidden" class="hfProdTax" value="' + row.taxGroupId + '" />' +
  8899. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="' + row.assesableAdjustment + '" />' +
  8900. '<input type="hidden" class="prodPrice text-center form-control" placeholder="0.00" value="0" />';
  8901. }
  8902. else {
  8903. html += '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  8904. '<input type="hidden" class="orderItemId" value="0" />' +
  8905. '<input type="hidden" class="dcItemId" value="0" />' +
  8906. '<input type="hidden" class="selectedInvoiceItemId" value="0" />' +
  8907. '<input type="hidden" class="selectedItemName" value="" />' +
  8908. '<input type="hidden" class="refInvoiceItemId" value="0" />' +
  8909. '<input type="hidden" class="selectedItemId" value="0" />' +
  8910. '<input type="hidden" class="inventorytypeid" value="0" />' +
  8911. '<input type="hidden" class="hfMrpId" value="0" />' +
  8912. '<input type="hidden" class="offerapplied" value="0" />' +
  8913. '<input type="hidden" class="refNo" value="0" />' +
  8914. '<input type="hidden" class="description" value="0" />' +
  8915. '<input type="hidden" class="IsExchangeItem" value="0" />' +
  8916. '<input type="hidden" class="maxQty" value="0" />' +
  8917. '<input type="hidden" class="hf_Account" value="0" />' +
  8918. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="0" />' +
  8919. '<input type="hidden" class="hfProdTax" value="0" />' +
  8920. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="0" />' +
  8921. '<input type="hidden" class="prodPrice text-center form-control" placeholder="0.00" value="0" />';
  8922. }
  8923. html += '<div class="input-group">' +
  8924. '<input type="hidden" class="hdnChargeTypeId" value="1" />' +
  8925. '<input type="hidden" class="hdnChargeLedgerId" value="' + ledgerId + '" />' +
  8926. '<a class="input-group-addon no-border bg-white delete" href="javascript:;" title="Remove row"><i class="fa fa-trash-o fa-lg mt-15 mr-2" style="margin-left:-25px;color:red"></i></a>';
  8927. html += '<select type="text" class="txtExpenseName ui-autocomplete form-control readonly" placeholder=" Expense name" value="' + discountname + '" style="width:100%;"></select>';
  8928. html += '<input type="hidden" class="hfSelectedChargeId" value="' + discountid + '" />' +
  8929. '</div>' +
  8930. '</div></div>' +
  8931. '<div class="col-sm-4">' +
  8932. '<div class="floating-label-form-group min-padding"><input type="text" class="expenseDesc form-control" placeholder="Description" value="' + description + '" /></div></div>' +
  8933. '<div class="col-sm-1">' +
  8934. '<div class="floating-label-form-group min-padding"><input type="text" class="exppercentage text-center form-control" placeholder="%" value="' + percent + '" /></div></div>' +
  8935. '<div class="col-sm-1">' +
  8936. '<div class="floating-label-form-group min-padding"><input type="text" class="expfixedvalue text-center form-control" placeholder="0.00" value="' + value + '" /></div></div>' +
  8937. '<div class="col-sm-2 mt-10"><p class="pull-right"><span class="' + rowname + '-total control-label mt-5">0</span></p></div>' +
  8938. '</div>';
  8939. $("." + rowname + ":last").after(html);
  8940. var element = $("." + rowname + ":last");
  8941. InvoiceItem.Instance().bind(element, inventorytypeid);
  8942. var txtChargeCode = element.find(".txtExpenseName");
  8943. var hfSelectedChargeId = element.find(".hfSelectedChargeId");
  8944. $(hfSelectedChargeId).val(hdnAutoId);
  8945. if (hdnAutoId != 0) {
  8946. var selecteditem = new Option(txtAutoSearchCtrl, hdnAutoId, true);
  8947. txtChargeCode.append(selecteditem);
  8948. }
  8949. if (rowname == "expense-row") {
  8950. var id = 0;
  8951. if (row != null) {
  8952. var selecteditem = new Option(row.itemName, row.itemId, true);
  8953. txtChargeCode.append(selecteditem);
  8954. }
  8955. let typeid = "7";
  8956. var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/itemautocompletebyinventorytype/inventorytypeid/' + Number(inventorytypeid) + '/lobid/' + $(".hfAutoCompleteId_lobid").val() + '/invoicetypeid/' + $('.hdn_invoicetypeid').val();
  8957. AutoCompleteHelper.getHelper().Create(txtChargeCode, hfSelectedChargeId, url, function (result) {
  8958. if (id != result.id) {
  8959. id = result.id;
  8960. var elementfordisc = $(".expense-row:last");
  8961. var hdnOrderItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[0];
  8962. var hdnSelectedItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[1];
  8963. InvoiceItem.Instance().loadItemRowDetails(element, 0, 0, hdnOrderItemIdVal);
  8964. }
  8965. });
  8966. }
  8967. $('.exppercentage').keypress(function (event) {
  8968. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  8969. }
  8970. else {
  8971. event.preventDefault();
  8972. }
  8973. }).on('paste', function (event) {
  8974. event.preventDefault();
  8975. });
  8976. $('.expfixedvalue').keypress(function (event) {
  8977. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  8978. }
  8979. else {
  8980. event.preventDefault();
  8981. }
  8982. }).on('paste', function (event) {
  8983. event.preventDefault();
  8984. });
  8985. }
  8986. loadItemRowDetails(element, orderItemId, dcItemId, itemId) {
  8987. var instance = this;
  8988. if (orderItemId == '' || ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4"))
  8989. orderItemId = 0;
  8990. if (dcItemId == '' || ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  8991. dcItemId = 0;
  8992. }
  8993. if ((orderItemId != 0 && orderItemId != undefined) || (itemId != 0 && itemId != undefined) || (dcItemId != 0 && dcItemId != undefined)) {
  8994. let lobId = $(".hfAutoCompleteId_lobid").val();
  8995. let billingAddressId = $('.txtAutoComplete_billtoaddressid').val();
  8996. if (billingAddressId == "0" || billingAddressId == "" || billingAddressId == null) {
  8997. MessageHelper.Instance().showError("Please select bill to address", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  8998. return false;
  8999. }
  9000. var portalId = 0;
  9001. var ShipfromAddressId = 0;
  9002. let invoiceid = $(".hdn_invoiceid").val();
  9003. if (invoiceid == undefined)
  9004. invoiceid = 0;
  9005. ShipfromAddressId = Number($(".txtAutoComplete_shipfromaddressid").val());
  9006. var ShiptoAddressId = Number($(".txtAutoComplete_shiptoaddressid").val());
  9007. portalId = Number($(".txtAutoComplete_billfromaddressid").val());
  9008. var MrpId = element.find(".hfMrpId").val();
  9009. if (MrpId == undefined)
  9010. MrpId = 0;
  9011. var isconfirm = false;
  9012. var invoicemode = "1";
  9013. var invoiceType = $('.hdn_invoicetypeid').val();
  9014. if (itemId == undefined)
  9015. itemId = 0;
  9016. var contactId = $(".hdn_organizationid").val();
  9017. if (contactId == 0)
  9018. contactId = $(".hfAutoCompleteId_orgcontactid").val();
  9019. var invoiceapplytype = 1;
  9020. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  9021. invoiceapplytype = 2;
  9022. }
  9023. let ApplyDate = new Date($('.hfdate_journaldate').val().toString());
  9024. var refinvoiceid = 0;
  9025. if ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0)
  9026. refinvoiceid = Number($(".hdn_refinvoiceid").val());
  9027. var post = {
  9028. OrderItemId: Number(orderItemId),
  9029. DcItemId: Number(dcItemId),
  9030. ItemId: Number(itemId),
  9031. BillingAddressId: Number(billingAddressId),
  9032. BillFromAddressId: portalId,
  9033. DefaultPriceListId: 0,
  9034. InvoiceType: Number(invoiceType),
  9035. MrpId: Number(MrpId),
  9036. InvoiceMode: Number(invoicemode),
  9037. isCform: Boolean(isconfirm),
  9038. LobId: Number(lobId),
  9039. contactId: Number(contactId),
  9040. InvoiceApplyType: invoiceapplytype,
  9041. ShipFromAddressId: ShipfromAddressId,
  9042. ShipToAddressId: ShiptoAddressId,
  9043. AutoDC: InvoiceItem.instance.AutoDc,
  9044. InvoiceDate: ApplyDate,
  9045. RefInvoiceId: refinvoiceid
  9046. };
  9047. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemDetails(post).then(function (response) {
  9048. var itemdata = response.result;
  9049. element.find(".selectedItemId").val(itemdata.ItemId);
  9050. if (itemdata.orderItemId == 0)
  9051. element.find(".orderItemId").val(orderItemId);
  9052. else
  9053. element.find(".orderItemId").val(itemdata.OrderItemId);
  9054. itemId = itemdata.ItemId;
  9055. element.find(".spnProdName").text(itemdata.ItemName);
  9056. element.find(".selectedItemName").text(itemdata.ItemName + ' - ' + itemdata.ItemSKU);
  9057. element.find("#inventorytypeid").val(itemdata.InventoryTypeId);
  9058. var prodPrice = element.find(".prodPrice");
  9059. var prodQty = element.find(".prodQuantity");
  9060. var priceListId = element.find(".hfPriceList");
  9061. var isSplitItem = false;
  9062. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  9063. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
  9064. isSplitItem = true;
  9065. }
  9066. }
  9067. if (itemdata.AccountId != 0 && (element.find(".selectedInvoiceItemId").val() == "0" || (itemdata.InventoryTypeId == 5)) && !isSplitItem) {
  9068. var selectedAccount = new Option(itemdata.AccountName, itemdata.AccountId, true);
  9069. element.find(".txt_Account").empty();
  9070. element.find(".txt_Account").append(selectedAccount);
  9071. element.find(".hf_Account").val(itemdata.AccountId);
  9072. element.find(".txt_AccountName").val(itemdata.AccountName);
  9073. }
  9074. if (itemdata.TaxGroupId != 0 && (element.find(".selectedInvoiceItemId").val() == "0" || (itemdata.InventoryTypeId == 5)) && !isSplitItem) {
  9075. var txtTaxGroup = element.find(".prodTax");
  9076. var hfTaxGroupId = element.find(".hfProdTax");
  9077. txtTaxGroup.empty();
  9078. var selectedTaxgrp = new Option(itemdata.TaxGroupName, itemdata.TaxGroupId, true);
  9079. txtTaxGroup.append(selectedTaxgrp);
  9080. element.find(".txtProdTax").val(itemdata.TaxGroupName);
  9081. hfTaxGroupId.val(itemdata.TaxGroupId);
  9082. InvoiceItem.Instance().update_tax(element, itemdata.TaxGroupId);
  9083. }
  9084. if (element.find(".selectedInvoiceItemId").val() == "0" && !isSplitItem) {
  9085. prodPrice.val(itemdata.UnitPrice);
  9086. element.find(".hf_UnitPrice").val(itemdata.UnitPrice);
  9087. priceListId.val(itemdata.PriceListId);
  9088. if (itemdata.AddlDisountValue > 0) {
  9089. element.find(".btnInvoice_DiscType option[value='Val']").prop("selected", true);
  9090. element.find('.inv_txtaddldiscount').val(itemdata.AddlDisountValue);
  9091. }
  9092. else if (itemdata.AddlDiscountPercent > 0) {
  9093. element.find(".btnInvoice_DiscType option[value='%']").prop("selected", true);
  9094. element.find('.inv_txtaddldiscount').val(itemdata.AddlDiscountPercent);
  9095. }
  9096. }
  9097. if ($(".hdn_invoiceid").val() != "0") {
  9098. element.find(".prodAvail").text(itemdata.AvailableQty);
  9099. element.find(".hfAvail").val(itemdata.AvailableQty);
  9100. }
  9101. else {
  9102. element.find(".prodAvail").text(itemdata.AvailableQty);
  9103. element.find(".hfAvail").val(itemdata.AvailableQty);
  9104. }
  9105. var dcid = InvoiceItem.Instance().dcid;
  9106. if (dcid == undefined)
  9107. dcid = 0;
  9108. if ((itemdata.EnableMrp == true || itemdata.EnableBatchNo == true || itemdata.EnableSerialNo == true) && ((Number(element.find('.prodAvail').text()) > 0) || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || dcid != 0) && $(".hdn_invoicetypeid").val() != "6" && $(".hdn_invoicetypeid").val() != "7" && element.find('.hf_IsFoc').val() == "false") {
  9109. element.find(".div_UnitPrice").addClass('hidden');
  9110. element.find(".div_SplitInvoiceItem").removeClass("hidden");
  9111. element.find(".prodQuantity").prop('disabled', true);
  9112. element.find(".prodQuantity").css('cursor', "not-allowed");
  9113. element.find("#inv_txtdiscount").prop('disabled', true);
  9114. element.find("#inv_txtdiscount").css('cursor', "not-allowed");
  9115. element.find('.btn_inv_DiscType').addClass('hidden');
  9116. element.find(".btn_inv_DiscType").prop('disabled', true);
  9117. element.find(".prodTax").removeClass("required");
  9118. element.find(".txt_Account").removeClass("required");
  9119. element.addClass('SplitItem');
  9120. var ItemExist = false;
  9121. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  9122. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
  9123. ItemExist = true;
  9124. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId == 0)
  9125. InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice = itemdata.UnitPrice;
  9126. }
  9127. }
  9128. var type = '';
  9129. if (itemdata.EnableBatchNo == true) {
  9130. if (ItemExist == true)
  9131. element.find(".spn_InvoiceItem").text("View BatchNo");
  9132. else
  9133. element.find(".spn_InvoiceItem").text("Select BatchNo");
  9134. type = "BatchNo";
  9135. }
  9136. else if (itemdata.EnableMrp == true) {
  9137. if (ItemExist == true)
  9138. element.find(".spn_InvoiceItem").text("View MRP");
  9139. else
  9140. element.find(".spn_InvoiceItem").text("Select MRP");
  9141. type = "MRP";
  9142. }
  9143. else {
  9144. if (ItemExist == true)
  9145. element.find(".spn_InvoiceItem").text("View SerialNo");
  9146. else
  9147. element.find(".spn_InvoiceItem").text("Select SerialNo");
  9148. type = 'SerialNo';
  9149. }
  9150. let d = InvoiceItem.instance.AutoDc;
  9151. if (d == false && dcItemId != 0 && element.find(".selectedInvoiceItemId").val() == "0") {
  9152. var Isitemadded = false;
  9153. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  9154. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId == dcItemId) {
  9155. Isitemadded = true;
  9156. }
  9157. }
  9158. if (Isitemadded == false) {
  9159. var IsSpitItem = false;
  9160. var RowTotal = 0;
  9161. var Discount = 0;
  9162. var Qty = 0;
  9163. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  9164. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
  9165. IsSpitItem = true;
  9166. }
  9167. }
  9168. InvoiceItem.Instance().SplitedInvoiceItemList.push({
  9169. orderItemId: itemdata.OrderItemId,
  9170. invoiceItemId: 0,
  9171. itemName: itemdata.ItemName,
  9172. itemId: itemdata.ItemId,
  9173. itemSKU: itemdata.ItemSKU,
  9174. unitName: itemdata.UnitName,
  9175. packSize: itemdata.PackSize,
  9176. packCount: itemdata.PackCount,
  9177. packs: itemdata.Packs,
  9178. quantity: itemdata.Quantity,
  9179. availPacks: itemdata.AvailablePacks,
  9180. availQty: itemdata.AvailableQty,
  9181. listPrice: 0,
  9182. description: itemdata.Description,
  9183. taxGroupName: itemdata.TaxGroupName,
  9184. taxGroupId: itemdata.TaxGroupId,
  9185. isTaxInclusive: $(".dropdown_istaxinclusive").val(),
  9186. addlDiscountPercent: itemdata.AddlDiscountPercent == undefined ? 0 : itemdata.AddlDiscountPercent,
  9187. addlDiscountValue: itemdata.AddlDisountValue,
  9188. creditNote: 0,
  9189. priceListId: 0,
  9190. batchId: 0,
  9191. unitPrice: itemdata.UnitPrice,
  9192. invoiceallocations: null,
  9193. exciseInvoiceItem: null,
  9194. accountId: itemdata.AccountId,
  9195. accountName: itemdata.AccountName,
  9196. walletId: 0,
  9197. Adjustment: 0,
  9198. IsFoc: false,
  9199. TariffNo: "",
  9200. exciseAmount: 0,
  9201. discountName: "",
  9202. discountId: 0,
  9203. refNo: itemdata.RefNo,
  9204. DiscountGroupId: 0,
  9205. DiscountGroupName: "",
  9206. ExchangeItem: false,
  9207. maxQty: itemdata.Quantity,
  9208. RefInvoiceItemId: 0,
  9209. MrpId: itemdata.MrpId,
  9210. taxAdjustment: 0,
  9211. assesableAdjustment: 0,
  9212. inventoryTypeId: itemdata.InventoryTypeId,
  9213. IsBoMItem: false,
  9214. dcItemId: dcItemId,
  9215. TotalRowAmount: 0,
  9216. TotalDiscount: 0,
  9217. TotalAmount: 0,
  9218. BatchId: itemdata.BatchId,
  9219. });
  9220. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  9221. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
  9222. Qty += InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity;
  9223. var rowtotal = Number((InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice) + InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount + itemdata.Adjustment);
  9224. var nonexiceamount = rowtotal - InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount;
  9225. var discount = ((nonexiceamount * itemdata.AddlDiscountPercent) / 100) + (itemdata.Quantity * itemdata.AddlDisountValue);
  9226. InvoiceItem.Instance().SplitedInvoiceItemList[i].TotalAmount = rowtotal,
  9227. InvoiceItem.Instance().SplitedInvoiceItemList[i].TotalDiscount = discount,
  9228. Discount += discount;
  9229. RowTotal += rowtotal;
  9230. }
  9231. }
  9232. $('.item-row').each(function () {
  9233. if ($(this).find('.selectedItemId').val() == itemdata.ItemId) {
  9234. if ($(".hdn_invoicetypeid").val() == "2") {
  9235. $(this).find(".txtRowTotalwithAdjustment").val();
  9236. $(this).find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(RowTotal), 3));
  9237. }
  9238. else {
  9239. element.find('.prodTotalPrice').text('');
  9240. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
  9241. }
  9242. $(this).find('.prodQuantity').val();
  9243. $(this).find('.prodQuantity').val(Qty);
  9244. $(this).find('#inv_txtdiscount').val();
  9245. $(this).find('#inv_txtdiscount').val(Discount);
  9246. }
  9247. });
  9248. }
  9249. }
  9250. if (orderItemId != 0 && invoiceid == 0) {
  9251. element.find('.prodQuantity').val(itemdata.Quantity);
  9252. }
  9253. element.find(".spn_InvoiceItem").unbind().click(function () {
  9254. InvoiceItem.Instance().createSplitItem(element, itemdata.ItemName + ' - ' + itemdata.ItemSKU, type);
  9255. });
  9256. }
  9257. else if (element.find(".selectedInvoiceItemId").val() == "0" && $('.hdn_invoicetypeid').val() != '3' && $('.hdn_invoicetypeid').val() != '4' && (dcItemId != 0 || (orderItemId != 0 && InvoiceItem.Instance().OrderSettingId == 2))) {
  9258. prodPrice.val(itemdata.UnitPrice);
  9259. prodQty.val(itemdata.Quantity);
  9260. priceListId.val(itemdata.PriceListId);
  9261. element.find('.maxQty').val(itemdata.Quantity);
  9262. }
  9263. if (element.find(".selectedInvoiceItemId").val() == "0" && ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  9264. prodQty.val(itemdata.Quantity);
  9265. }
  9266. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
  9267. if ((itemdata.IsOfferAvailable == true || itemdata.IsFocAvailable == true) && element.find('.hf_IsFoc').val() != "true") {
  9268. element.find('.btn_offer').removeClass('hidden');
  9269. element.find('.btn_offer').click(function () {
  9270. InvoiceItem.Instance().loadItemOffers(itemdata.ItemId, itemdata.ItemName, invoiceapplytype, contactId, element);
  9271. });
  9272. }
  9273. else
  9274. element.find('.btn_offer').addClass('hidden');
  9275. if (itemdata.IsSpecialPrice == true)
  9276. element.find('.btn_specialPrice').removeClass('hidden');
  9277. }
  9278. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $("#hf_AppSettingName").val() == "Create Return") {
  9279. element.find(".prodTax").empty();
  9280. element.find(".txt_Account").empty();
  9281. if (itemdata.TaxGroupId != 0) {
  9282. element.find(".txtProdTax").val(itemdata.TaxGroupName);
  9283. element.find(".hfProdTax").val(itemdata.TaxGroupId);
  9284. }
  9285. if (itemdata.AccountId != 0) {
  9286. element.find(".hf_Account").val(itemdata.AccountId);
  9287. element.find(".txt_AccountName").val(itemdata.AccountName);
  9288. }
  9289. }
  9290. if (!element.hasClass('SplitItem')) {
  9291. if ($(".hdn_invoiceid").val() != "0" && $(".hdn_invoiceid").val() != undefined) {
  9292. var taxgrpid = element.find(".hfProdTax").val();
  9293. InvoiceItem.Instance().update_tax(element, taxgrpid);
  9294. }
  9295. }
  9296. if (!element.hasClass('SplitItem') && (element.find(".selectedInvoiceItemId").val() == "0" || element.find(".selectedInvoiceItemId").val() == "undefined")) {
  9297. var txtTaxGroup = element.find(".prodTax");
  9298. var hfTaxGroupId = element.find(".hfProdTax");
  9299. if (itemdata.TaxGroupId != 0) {
  9300. txtTaxGroup.empty();
  9301. var selectedTaxgrp = new Option(itemdata.TaxGroupName, itemdata.TaxGroupId, true);
  9302. txtTaxGroup.append(selectedTaxgrp);
  9303. element.find(".txtProdTax").val(itemdata.TaxGroupName);
  9304. hfTaxGroupId.val(itemdata.TaxGroupId);
  9305. InvoiceItem.Instance().update_tax(element, itemdata.TaxGroupId);
  9306. }
  9307. if (itemdata.AccountId != 0) {
  9308. var selectedAccount = new Option(itemdata.AccountName, itemdata.AccountId, true);
  9309. element.find(".txt_Account").empty();
  9310. element.find(".txt_Account").append(selectedAccount);
  9311. element.find(".hf_Account").val(itemdata.AccountId);
  9312. element.find(".txt_AccountName").val(itemdata.AccountName);
  9313. }
  9314. }
  9315. var unit = element.find(".unit");
  9316. unit.text(itemdata.UnitName);
  9317. var sku = element.find(".prodSKU");
  9318. sku.text(itemdata.ItemSKU);
  9319. var packSize = element.find(".packSize");
  9320. if (itemdata.PackSize == "0")
  9321. packSize.val("1");
  9322. else
  9323. packSize.val(itemdata.PackSize);
  9324. if (itemdata.PackCount == "0")
  9325. element.find(".packCount").val("1");
  9326. else
  9327. element.find(".packCount").val(itemdata.PackCount);
  9328. var rowTotal = 0;
  9329. var rowTotalwithAdjustment = 0;
  9330. if (element.find('.prodPrice').val() != undefined && element.find('.prodQuantity').val() != undefined) {
  9331. rowTotal = element.find('.prodPrice').val().replace("$", "") * element.find('.prodQuantity').val();
  9332. rowTotalwithAdjustment = element.find('.prodPrice').val().replace("$", "") * element.find('.prodQuantity').val();
  9333. }
  9334. if (itemdata.InventoryTypeId == 2) {
  9335. element.find('.prodQuantity').removeAttr('readonly');
  9336. }
  9337. var asbAdjAmt = element.find('.hfItemAssesableAdjustmentVal').val();
  9338. if (!isNaN(asbAdjAmt))
  9339. rowTotalwithAdjustment += Number(asbAdjAmt);
  9340. rowTotalwithAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotalwithAdjustment, 2);
  9341. if (isNaN(rowTotal)) {
  9342. if (!element.hasClass('SplitItem')) {
  9343. element.find('.prodTotalPrice').html("N/A");
  9344. element.find('.hfRowTotal').val("0");
  9345. element.find('.hfRowTotalwithAdjustment').val("0");
  9346. }
  9347. }
  9348. else {
  9349. if (!element.hasClass('SplitItem')) {
  9350. element.find('.hfRowTotal').val(rowTotal);
  9351. element.find('.hfRowTotalwithAdjustment').val(rowTotalwithAdjustment);
  9352. element.find('.prodTotalPrice').html(rowTotal);
  9353. }
  9354. }
  9355. if (itemdata.AvailableQty <= 0)
  9356. element.find(".prodAvail").addClass('text-danger');
  9357. else
  9358. element.find(".prodAvail").removeClass('text-danger');
  9359. if (!element.hasClass('SplitItem')) {
  9360. InvoiceItem.Instance().update_row_total(element, false);
  9361. }
  9362. InvoiceItem.Instance().loadPriceLists(element, itemId, itemdata.EnableMrp);
  9363. if (itemdata.EnableMrp != true && itemdata.EnableBatchNo != true && itemdata.EnableSerialNo != true) {
  9364. element.find('.hfRowTotalwithAdjustment').css("text-decoration", "underline");
  9365. element.find('.hfRowTotalwithAdjustment').attr("disabled", false);
  9366. element.find('.Adjustmentrow').click(function () {
  9367. if ($(".hdn_invoicetypeid").val() == "2" && element.find('.selectedInvoiceItemId').val() != "0") {
  9368. InvoiceItem.Instance().editInvItemTaxAllocs(element.find('.selectedInvoiceItemId').val(), element.find('.hfProdTax').val(), element.find('.selectedItemId').val(), element.find('.orderItemId').val(), element);
  9369. }
  9370. });
  9371. }
  9372. else {
  9373. element.find('.hfRowTotalwithAdjustment').css("text-decoration", "");
  9374. element.find('.hfRowTotalwithAdjustment').attr("disabled", true);
  9375. }
  9376. if (IsSpitItem == true) {
  9377. element.remove();
  9378. }
  9379. if (itemdata.IsMultilpeUOMs && $(".hdn_invoicetypeid").val() == "1") {
  9380. element.find(".hf_IsMultipleUOM").val(itemdata.IsMultilpeUOMs);
  9381. let MultipleUOMs = itemdata.MultipleUoms;
  9382. let html = '<option value="0"> -- Select -- </option>';
  9383. for (var i = 0; i < MultipleUOMs.length; i++) {
  9384. html += '<option value="' + MultipleUOMs[i].SchemaDetailId + '">' + MultipleUOMs[i].AlternateUnitName + ' ( ' + MultipleUOMs[i].DefaultSize + ' ' + MultipleUOMs[i].DefaultUnitName + ' ) </option>';
  9385. }
  9386. element.find(".ddl_MultipleUOMs").html(html);
  9387. element.find("#div_MultipleUOMs").removeClass("hidden");
  9388. instance.UOMs.push({
  9389. ItemId: itemId,
  9390. MultipleUOMs: MultipleUOMs
  9391. });
  9392. let SelectedUOM = Number(element.find(".hf_AlternateUnitId").val());
  9393. let DefaultSize = Number(element.find(".hf_DefaultSize").val());
  9394. if (SelectedUOM != 0) {
  9395. element.find(".ddl_MultipleUOMs").val(SelectedUOM);
  9396. let Qty = element.find(".prodQuantity").val();
  9397. let NewQty = Qty / DefaultSize;
  9398. element.find(".prodQuantity").val(NewQty);
  9399. }
  9400. }
  9401. else {
  9402. element.find("#div_MultipleUOMs").addClass("hidden");
  9403. }
  9404. if (itemdata.InventoryTypeId == 1)
  9405. InvoiceItem.Instance().GetDiscounts();
  9406. }, function (response) {
  9407. MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  9408. });
  9409. }
  9410. }
  9411. loadItemOffers(ItemId, ItemName, InvoiceApplyType, OrganizationId, element) {
  9412. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/components/invoices/itemofferselection.js", function () {
  9413. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(0, "", Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance(), function () {
  9414. Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance().LoadOfferItems(OrganizationId, ItemId, ItemName, InvoiceApplyType, element, "Invoice");
  9415. }, Unibase.Platform.Helpers.Size.Large);
  9416. });
  9417. }
  9418. update_tax(element, taxGroupId) {
  9419. var hfTaxValue = element.find(".hfProdTaxValue");
  9420. var hfTaxPercent = element.find(".hfProdTaxPercent");
  9421. var hfProdTax = element.find(".hfProdTax");
  9422. var percentage = 0;
  9423. if (taxGroupId == "0" || taxGroupId == "" || taxGroupId == undefined)
  9424. return percentage;
  9425. let branchid = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  9426. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().gettaxpercentages(taxGroupId, branchid).then(function (response) {
  9427. var percentstring = "";
  9428. if (response.result.length > 0) {
  9429. var percentages = response.result;
  9430. for (var i = 0; i < percentages.length; i++) {
  9431. percentstring += percentages[i].LedgerId + ":" + percentages[i].Percentage + ",";
  9432. }
  9433. hfTaxPercent.val(percentstring);
  9434. }
  9435. hfTaxValue.val("0");
  9436. InvoiceItem.Instance().update_total();
  9437. InvoiceItem.Instance().TotalAdjustment();
  9438. }, function (response) {
  9439. MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  9440. });
  9441. }
  9442. createSplitItem(element, ItemName, type) {
  9443. let obj = [];
  9444. obj.push({
  9445. type: type,
  9446. element: element,
  9447. });
  9448. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/invoices/splititem.js", function () {
  9449. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(obj, "", Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance(), null, Unibase.Platform.Helpers.Size.Large);
  9450. });
  9451. }
  9452. loadPriceLists(element, itemId, IsEnableMrp) {
  9453. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getLatestMrpByItemId(itemId).then(function (response) {
  9454. if (response.result != null) {
  9455. element.find(".hf_PriceList").val(response.result.PriceListId);
  9456. if (response.result.MrpId != 0 && IsEnableMrp) {
  9457. element.find(".txt_MRP").val(response.result.Mrp);
  9458. element.find(".hfMrpId").val(response.result.MrpId);
  9459. }
  9460. }
  9461. }, function (response) {
  9462. MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  9463. });
  9464. }
  9465. RemoveItem(element) {
  9466. var _this = element.find(".delete");
  9467. var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
  9468. if (invoiceitemid == "0") {
  9469. $(element).find(".prodTax").removeClass("required");
  9470. $(element).find(".txt_Account").removeClass("required");
  9471. $(element).addClass("hidden remove_item");
  9472. $(element).find(".selectedItemId").val(0);
  9473. }
  9474. else {
  9475. _this.parents('.item-row').remove();
  9476. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  9477. }
  9478. InvoiceItem.Instance().update_total();
  9479. InvoiceItem.Instance().TotalAdjustment();
  9480. }
  9481. bind(element, inventoryTypeId) {
  9482. if (inventoryTypeId != 5 && inventoryTypeId != 6 && inventoryTypeId != 7) {
  9483. element.find(".delete").on('click', function () {
  9484. var _this = $(this);
  9485. var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
  9486. if (_this.parents('.item-row').hasClass('SplitItem')) {
  9487. bootbox.confirm("You are about to delete the invoice items. Are you sure?", function (result) {
  9488. if (result == true) {
  9489. var orderid = _this.parents('.item-row').find('.orderItemId').val();
  9490. if ((orderid == 0 || orderid == "0" || orderid == undefined) && _this.parents('.item-row').find('.selectedItemId').val() != 0) {
  9491. let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
  9492. if (index == -1)
  9493. index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
  9494. if (index > -1) {
  9495. InvoiceItem.Instance().itemIds.splice(index, 1);
  9496. }
  9497. }
  9498. else if (orderid != 0) {
  9499. let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
  9500. if (index == -1)
  9501. index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
  9502. if (index > -1) {
  9503. InvoiceItem.Instance().itemIds.splice(index, 1);
  9504. }
  9505. var itemlength = InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.itemId == Number(_this.parents('.item-row').find('.selectedItemId').val()));
  9506. if (itemlength == undefined) {
  9507. if (_this.parents('.item-row').find('.selectedInvoiceItemId').val() != 0) {
  9508. InvoiceItem.Instance().deleted_invoiceItems.push(Number(_this.parents('.item-row').find('.selectedInvoiceItemId').val()));
  9509. }
  9510. }
  9511. }
  9512. var x = [];
  9513. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  9514. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == _this.parents('.item-row').find('.selectedItemId').val()) {
  9515. x.push(i);
  9516. var index = InvoiceItem.Instance().dcItemIds.indexOf(InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId);
  9517. if (index == -1)
  9518. index = InvoiceItem.Instance().dcItemIds.indexOf(Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId));
  9519. if (index > -1) {
  9520. InvoiceItem.Instance().dcItemIds.splice(index, 1);
  9521. }
  9522. if (InvoiceItem.Instance().dcItemIds.length == 0)
  9523. InvoiceItem.Instance().dcItemIds = [0];
  9524. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId != 0) {
  9525. InvoiceItem.Instance().deleted_invoiceItems.push(Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId));
  9526. }
  9527. }
  9528. }
  9529. $('.item-row').each(function () {
  9530. if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true") {
  9531. if ($(this).find('.selectedInvoiceItemId').val() != 0)
  9532. InvoiceItem.Instance().deleted_invoiceItems.push(Number($(this).find('.selectedInvoiceItemId').val()));
  9533. $(this).remove();
  9534. }
  9535. });
  9536. for (var i = x.length - 1; i >= 0; i--) {
  9537. InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
  9538. }
  9539. _this.parents('.item-row').remove();
  9540. $("#txt_Adjustment").val("0");
  9541. InvoiceItem.Instance().update_total();
  9542. InvoiceItem.Instance().TotalAdjustment();
  9543. InvoiceItem.Instance().GetDiscounts();
  9544. }
  9545. });
  9546. }
  9547. else if (invoiceitemid != 0) {
  9548. bootbox.confirm("You are about to delete the invoice items. Are you sure?", function (result) {
  9549. if (result) {
  9550. var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
  9551. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  9552. var orderitemid = _this.parents('.item-row').find('.orderItemId').val();
  9553. var dcitemid = _this.parents('.item-row').find('.dcItemId').val();
  9554. if (_this.parents('.item-row').find('.selectedItemId').val() != 0) {
  9555. let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
  9556. if (index == -1)
  9557. index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
  9558. if (index > -1) {
  9559. InvoiceItem.Instance().itemIds.splice(index, 1);
  9560. }
  9561. if (orderitemid != 0 && dcitemid != 0) {
  9562. let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(_this.parents('.item-row').find('.dcItemId').val(), 0);
  9563. if (dcindex == -1)
  9564. dcindex = InvoiceItem.Instance().dcItemIds.indexOf(Number(_this.parents('.item-row').find('.dcItemId').val()), 0);
  9565. InvoiceItem.Instance().dcItemIds.splice(dcindex, 1);
  9566. if (InvoiceItem.Instance().dcItemIds.length == 0)
  9567. InvoiceItem.Instance().dcItemIds.push(0);
  9568. }
  9569. }
  9570. $('.item-row').each(function () {
  9571. if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true")
  9572. $(this).remove();
  9573. });
  9574. _this.parents('.item-row').remove();
  9575. $("#txt_Adjustment").val("0");
  9576. InvoiceItem.Instance().update_total();
  9577. InvoiceItem.Instance().TotalAdjustment();
  9578. InvoiceItem.Instance().GetDiscounts();
  9579. }
  9580. });
  9581. }
  9582. else {
  9583. bootbox.confirm("You are about to delete the invoice item. Are you sure?", function (result) {
  9584. if (result) {
  9585. var dcitemid = _this.parents('.item-row').find('.dcItemId').val();
  9586. if (_this.parents('.item-row').find('.selectedItemId').val() != 0) {
  9587. let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
  9588. if (index == -1)
  9589. index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
  9590. if (index > -1) {
  9591. InvoiceItem.Instance().itemIds.splice(index, 1);
  9592. if (dcitemid != 0) {
  9593. let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(Number(_this.parents('.item-row').find('.dcItemId').val()), 0);
  9594. InvoiceItem.Instance().dcItemIds.splice(dcindex, 1);
  9595. if (InvoiceItem.Instance().dcItemIds.length == 0)
  9596. InvoiceItem.Instance().dcItemIds.push(0);
  9597. }
  9598. }
  9599. }
  9600. var x = [];
  9601. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  9602. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == _this.parents('.item-row').find('.selectedItemId').val()) {
  9603. x.push(i);
  9604. }
  9605. }
  9606. for (var i = x.length - 1; i >= 0; i--) {
  9607. InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
  9608. }
  9609. $('.item-row').each(function () {
  9610. if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true")
  9611. $(this).remove();
  9612. });
  9613. _this.parents('.item-row').remove();
  9614. $("#txt_Adjustment").val("0");
  9615. InvoiceItem.Instance().update_total();
  9616. InvoiceItem.Instance().TotalAdjustment();
  9617. InvoiceItem.Instance().GetDiscounts();
  9618. }
  9619. });
  9620. }
  9621. });
  9622. element.find(".prodPrice,.prodQuantity,.exciseAmount").blur(function () {
  9623. InvoiceItem.Instance().update_price(element);
  9624. });
  9625. element.find(".prodQuantity").change(function () {
  9626. InvoiceItem.Instance().CheckOfferForItem($(this));
  9627. });
  9628. element.find(".prodTax").blur(function () {
  9629. InvoiceItem.Instance().update_total();
  9630. InvoiceItem.Instance().TotalAdjustment();
  9631. });
  9632. element.find(".prodPrice").blur(function () {
  9633. InvoiceItem.Instance().update_total();
  9634. InvoiceItem.Instance().TotalAdjustment();
  9635. InvoiceItem.Instance().GetDiscounts();
  9636. });
  9637. element.find(".prodQuantity").blur(function () {
  9638. InvoiceItem.Instance().update_total();
  9639. InvoiceItem.Instance().TotalAdjustment();
  9640. InvoiceItem.Instance().GetDiscounts();
  9641. });
  9642. element.find('.ddl_MultipleUOMs').change(function () {
  9643. InvoiceItem.Instance().update_row_total(element, true);
  9644. });
  9645. element.find(".inv_txtaddldiscount").blur(function () {
  9646. InvoiceItem.Instance().update_total();
  9647. InvoiceItem.Instance().TotalAdjustment();
  9648. InvoiceItem.Instance().GetDiscounts();
  9649. });
  9650. element.find(".inv_txtaddldiscount").blur(InvoiceItem.Instance().update_discount_total);
  9651. element.find(".btnOrder_DiscType").text('Val');
  9652. element.find(".btnInvoice_DiscType").change(function () {
  9653. if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Val') {
  9654. element.find('#hfProdDiscountGroupId').val(0);
  9655. element.find('#hfProdDiscountGroupName').val('');
  9656. element.find('.inv_txtaddldiscount').prop('disabled', false);
  9657. }
  9658. else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == '%') {
  9659. element.find('#hfProdDiscountGroupId').val(0);
  9660. element.find('#hfProdDiscountGroupName').val('');
  9661. element.find('.inv_txtaddldiscount').prop('disabled', false);
  9662. if (Number(element.find("#inv_txtdiscount").val()) > 100) {
  9663. element.find("#inv_txtdiscount").val("100");
  9664. }
  9665. }
  9666. InvoiceItem.Instance().update_total();
  9667. InvoiceItem.Instance().TotalAdjustment();
  9668. InvoiceItem.Instance().GetDiscounts();
  9669. });
  9670. }
  9671. else {
  9672. if (inventoryTypeId == 6) {
  9673. element.find(".delete").on('click', function () {
  9674. var dis = $(".fixedvalue").val();
  9675. var _this = $(this);
  9676. var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
  9677. if (selectedinvoiceitemid != 0) {
  9678. bootbox.confirm("You are about to delete the discount item. Are you sure?", function (result) {
  9679. if (result) {
  9680. var rowIndex = element.find(".rowIndex").val();
  9681. var invoiceitemid = _this.parents('.discount-row').find(".selectedInvoiceItemId").val();
  9682. _this.parents('.discount-row').remove();
  9683. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  9684. }
  9685. InvoiceItem.Instance().update_total();
  9686. InvoiceItem.Instance().TotalAdjustment();
  9687. });
  9688. }
  9689. else {
  9690. _this.parents('.discount-row').remove();
  9691. InvoiceItem.Instance().update_total();
  9692. InvoiceItem.Instance().TotalAdjustment();
  9693. }
  9694. InvoiceItem.Instance().update_total();
  9695. InvoiceItem.Instance().TotalAdjustment();
  9696. });
  9697. }
  9698. else if (inventoryTypeId == 5) {
  9699. element.find(".delete").on('click', function () {
  9700. var dis = $(".fixedvalue").val();
  9701. var _this = $(this);
  9702. var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
  9703. if (selectedinvoiceitemid != 0) {
  9704. bootbox.confirm("You are about to delete the coupon item. Are you sure?", function (result) {
  9705. if (result) {
  9706. var rowIndex = element.find(".rowIndex").val();
  9707. var invoiceitemid = _this.parents('.netdiscount-row').find(".selectedInvoiceItemId").val();
  9708. _this.parents('.netdiscount-row').remove();
  9709. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  9710. }
  9711. InvoiceItem.Instance().update_total();
  9712. InvoiceItem.Instance().TotalAdjustment();
  9713. });
  9714. }
  9715. else {
  9716. if (_this.parents('.OnInvoiceOfferItem').length != 0) {
  9717. InvoiceItem.Instance().isOfferChargeApplied = false;
  9718. $(".hdn_isofferchargeapplied").val('false');
  9719. }
  9720. _this.parents('.netdiscount-row').remove();
  9721. InvoiceItem.Instance().update_total();
  9722. InvoiceItem.Instance().TotalAdjustment();
  9723. }
  9724. InvoiceItem.Instance().update_total();
  9725. InvoiceItem.Instance().TotalAdjustment();
  9726. });
  9727. }
  9728. else if (inventoryTypeId == 7) {
  9729. element.find(".delete").on('click', function () {
  9730. var dis = $(".expfixedvalue").val();
  9731. var _this = $(this);
  9732. var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
  9733. if (selectedinvoiceitemid != 0) {
  9734. bootbox.confirm("You are about to delete the coupon item. Are you sure?", function (result) {
  9735. if (result) {
  9736. var rowIndex = element.find(".rowIndex").val();
  9737. var invoiceitemid = _this.parents('.expense-row').find(".selectedInvoiceItemId").val();
  9738. _this.parents('.expense-row').remove();
  9739. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  9740. }
  9741. InvoiceItem.Instance().update_total();
  9742. InvoiceItem.Instance().TotalAdjustment();
  9743. });
  9744. }
  9745. else {
  9746. _this.parents('.expense-row').remove();
  9747. InvoiceItem.Instance().update_total();
  9748. InvoiceItem.Instance().TotalAdjustment();
  9749. }
  9750. InvoiceItem.Instance().update_total();
  9751. InvoiceItem.Instance().TotalAdjustment();
  9752. });
  9753. }
  9754. $(".percentage").on('blur', function () {
  9755. InvoiceItem.Instance().update_discount_total();
  9756. });
  9757. $(".fixedvalue").on('blur', function () {
  9758. InvoiceItem.Instance().update_discount_total();
  9759. });
  9760. $(".expfixedvalue").on('blur', function () {
  9761. InvoiceItem.Instance().update_expense_total();
  9762. });
  9763. $(".exppercentage").on('blur', function () {
  9764. InvoiceItem.Instance().update_expense_total();
  9765. });
  9766. InvoiceItem.Instance().update_discount_total();
  9767. InvoiceItem.Instance().update_expense_total();
  9768. }
  9769. }
  9770. update_price(element) {
  9771. InvoiceItem.Instance().update_row_total(element, true);
  9772. }
  9773. update_row_total(element, checkavailability) {
  9774. var row = element;
  9775. var item = Number(row.find('.selectedItemId').val());
  9776. var inventorytypeid = 0;
  9777. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
  9778. Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItem(item).then(function (response) {
  9779. inventorytypeid = response.result.InventoryTypeId;
  9780. if (item == 0) {
  9781. row.find(".prodQuantity").val(0);
  9782. row.find(".prodPrice").val(0);
  9783. MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  9784. return false;
  9785. }
  9786. if (checkavailability == true) {
  9787. let BranchId = 0;
  9788. var SettingName = "";
  9789. if ($(".hdn_invoicetypeid").val() == "1") {
  9790. SettingName = "Bizgaze_Extension_Transact_Orders_Setting_Sales_CheckAvailability";
  9791. BranchId = Number($(".txtAutoComplete_billfromaddressid option:selected").val());
  9792. }
  9793. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/orders/ordermanager.js", function () {
  9794. let LobId = Number($(".txtAutoComplete_lobid option:selected").val());
  9795. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getOrderSettingsByLob(SettingName, LobId, BranchId).then(function (res) {
  9796. let IsCheckAvailability_Lob = res.result.SettingValue;
  9797. if (IsCheckAvailability_Lob == "Yes" || res.result == "") {
  9798. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && (InvoiceItem.Instance().OrderSettingId == 2 || InvoiceItem.Instance().AutoDc == true)) {
  9799. if ($(".hdn_invoiceid").val() == "0") {
  9800. if (Number(row.find('.prodQuantity').val()) > Number(row.find('.prodAvail').text()) && inventorytypeid != 2) {
  9801. MessageHelper.Instance().showError("Check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  9802. if (Number(row.find('.prodAvail').text()) > 0)
  9803. row.find('.prodQuantity').val(row.find('.prodAvail').text());
  9804. else {
  9805. row.find('.prodQuantity').val("0");
  9806. }
  9807. }
  9808. }
  9809. else {
  9810. let Qty = Number(row.find('.prodQuantity').val());
  9811. let AvQty = Number(row.find('.prodAvail').text()) + Number(row.find('.Qty').val());
  9812. if (Qty > AvQty && inventorytypeid != 2) {
  9813. MessageHelper.Instance().showError("Check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  9814. row.find('.prodQuantity').val(row.find('.Qty').val());
  9815. }
  9816. }
  9817. }
  9818. if (row.find('.orderItemId').val() != 0 && !row.hasClass('.SplitItem')) {
  9819. if (Number(row.find('.prodQuantity').val()) > Number(row.find('.maxQty').val())) {
  9820. row.find('.prodQuantity').val(Number(row.find('.maxQty').val()));
  9821. InvoiceItem.Instance().update_row_total(element, checkavailability);
  9822. InvoiceItem.Instance().GetDiscounts();
  9823. }
  9824. }
  9825. }
  9826. });
  9827. });
  9828. }
  9829. var rowTotal = 0;
  9830. var rowTotalwithAdjustment = 0;
  9831. if (row.find('.prodPrice').val() != undefined && row.find('.prodQuantity').val() != undefined) {
  9832. rowTotal = row.find('.prodPrice').val().replace("$", "") * (Number(row.find('.prodQuantity').val()));
  9833. rowTotalwithAdjustment = row.find('.prodPrice').val().replace("$", "") * (Number(row.find('.prodQuantity').val()));
  9834. }
  9835. rowTotal += Number(row.find('.hfRowTotalAdjustment').val());
  9836. rowTotalwithAdjustment += Number(row.find('.hfRowTotalAdjustment').val());
  9837. var exciseAmount = element.find(".exciseAmount").val();
  9838. if (exciseAmount != undefined) {
  9839. rowTotal += Number(exciseAmount);
  9840. rowTotalwithAdjustment += Number(exciseAmount);
  9841. }
  9842. var asbAdjAmt = 0;
  9843. asbAdjAmt = row.find('.hfItemAssesableAdjustmentVal').val();
  9844. if (!isNaN(asbAdjAmt))
  9845. rowTotalwithAdjustment += Number(asbAdjAmt);
  9846. rowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotal, 2);
  9847. rowTotalwithAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotalwithAdjustment, 2);
  9848. if (isNaN(rowTotal)) {
  9849. element.find('.prodTotalPrice').html("N/A");
  9850. element.find('.hfRowTotal').val("0");
  9851. element.find('.hfRowTotalwithAdjustment').val("0");
  9852. }
  9853. else {
  9854. element.find('.hfRowTotal').val(rowTotal);
  9855. element.find('.hfRowTotalwithAdjustment').val(rowTotalwithAdjustment);
  9856. element.find('.prodTotalPrice').html(rowTotal);
  9857. }
  9858. InvoiceItem.Instance().update_total();
  9859. InvoiceItem.Instance().TotalAdjustment();
  9860. InvoiceItem.Instance().update_discount_total();
  9861. });
  9862. });
  9863. }
  9864. CheckOfferForItem(control) {
  9865. var element = control.parents('.item-row');
  9866. if (element.find('.orderItemId').val() == 0) {
  9867. if ($(".hdn_invoicetypeid").val() == "1") {
  9868. if (Number(element.find('.prodQuantity').val()) <= Number(element.find('.prodAvail').text())) {
  9869. InvoiceItem.Instance().GetPlanItems(element.find('.selectedItemId').val(), element.find('.prodQuantity').val(), element);
  9870. }
  9871. }
  9872. else if ($(".hdn_invoicetypeid").val() == "2") {
  9873. InvoiceItem.Instance().GetPlanItems(element.find('.selectedItemId').val(), element.find('.prodQuantity').val(), element);
  9874. }
  9875. }
  9876. }
  9877. GetPlanItems(ItemId, Quantity, element) {
  9878. var contactId = $(".hdn_organizationid").val();
  9879. if (contactId == 0)
  9880. contactId = $(".hfAutoCompleteId_orgcontactid").val();
  9881. var invoiceapplytype = 1;
  9882. var RowTotal = Number(element.find('.prodTotalPrice').text());
  9883. if ($(".hdn_invoicetypeid").val() == "2") {
  9884. invoiceapplytype = 2;
  9885. RowTotal = Number(element.find(".txtRowTotalwithAdjustment").val());
  9886. }
  9887. $('.item-row').each(function () {
  9888. if ($(this).find('.hfOfferedItemId').val() == ItemId) {
  9889. if ($(this).find('.selectedInvoiceItemId').val() != "0")
  9890. InvoiceItem.Instance().deleted_invoiceItems.push(Number($(this).find('.selectedInvoiceItemId').val()));
  9891. $(this).remove();
  9892. }
  9893. });
  9894. let ApplyDate = moment($('.hfdate_journaldate').val().toString(), "YYYY/MM/DD").format("YYYY-MM-DD");
  9895. Bizgaze.Apps.Transact.Managers.OfferManager.Instance().getoffers(ItemId, Number(contactId), Quantity, invoiceapplytype, RowTotal, ApplyDate).then(function (result) {
  9896. var response = result.result;
  9897. if (response.length > 0) {
  9898. for (var j = 0; j < response.length; j++) {
  9899. if (element.hasClass('SplitItem')) {
  9900. var RowTotal = 0;
  9901. var rowDiscount = 0;
  9902. for (var k = 0; k < InvoiceItem.Instance().SplitedInvoiceItemList.length; k++) {
  9903. if (InvoiceItem.Instance().SplitedInvoiceItemList[k].itemId == ItemId) {
  9904. var discValue = 0;
  9905. var discPercent = 0;
  9906. var Itemrow = InvoiceItem.Instance().SplitedInvoiceItemList[k];
  9907. if (response[j].PayoutValue > 0) {
  9908. discValue = response[j].PayoutValue;
  9909. Itemrow.addlDiscountValue = discValue;
  9910. Itemrow.addlDiscountPercent = 0;
  9911. }
  9912. else if (response[j].PayoutPercent > 0) {
  9913. discPercent = response[j].PayoutPercent;
  9914. Itemrow.addlDiscountPercent = discPercent;
  9915. Itemrow.addlDiscountValue = 0;
  9916. }
  9917. var TotalLineAmount = (Number(Itemrow.quantity) * Number(Itemrow.unitPrice)) + Number(Itemrow.exciseAmount) + Number(Itemrow.Adjustment) + Number(Itemrow.assesableAdjustment);
  9918. var NonExciseAmount = TotalLineAmount - Number(Itemrow.exciseAmount);
  9919. var DiscountAmount = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(NonExciseAmount * (Number(Itemrow.addlDiscountPercent) / 100) + (Number(Itemrow.quantity) * Number(Itemrow.addlDiscountValue)), 2);
  9920. Itemrow.DiscountedAmount = DiscountAmount;
  9921. Itemrow.TotalAmount = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((TotalLineAmount - Number(DiscountAmount)), 3);
  9922. RowTotal += Number(Itemrow.TotalAmount);
  9923. rowDiscount += Number(DiscountAmount);
  9924. }
  9925. }
  9926. if ($(".hdn_invoicetypeid").val() == "2") {
  9927. element.find(".txtRowTotalwithAdjustment").val();
  9928. element.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
  9929. element.find('#inv_txtdiscount').val();
  9930. element.find('#inv_txtdiscount').val(rowDiscount);
  9931. }
  9932. else {
  9933. element.find('.prodTotalPrice').text('');
  9934. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
  9935. element.find('#inv_txtdiscount').val();
  9936. element.find('#inv_txtdiscount').val(rowDiscount);
  9937. }
  9938. }
  9939. else {
  9940. var discValue = 0;
  9941. var discPercent = 0;
  9942. if (response[j].PayoutValue > 0) {
  9943. discValue = response[j].PayoutValue;
  9944. element.find(".btnInvoice_DiscType option[value='Val']").prop("selected", true);
  9945. element.find('.inv_txtaddldiscount').val(discValue);
  9946. }
  9947. else if (response[j].PayoutPercent > 0) {
  9948. discPercent = response[j].PayoutPercent;
  9949. element.find(".btnInvoice_DiscType option[value='%']").prop("selected", true);
  9950. element.find('.inv_txtaddldiscount').val(discPercent);
  9951. }
  9952. }
  9953. if (response[j].ItemVolumePayouts.length > 0) {
  9954. var OfferItems = response[j].ItemVolumePayouts;
  9955. for (var i = 0; i < OfferItems.length; i++) {
  9956. var emptyRow = {
  9957. orderItemId: 0,
  9958. invoiceItemId: 0,
  9959. itemName: OfferItems[i].ItemName,
  9960. itemId: OfferItems[i].ItemId,
  9961. itemSKU: "",
  9962. unitName: "",
  9963. packSize: 0,
  9964. packCount: 0,
  9965. packs: 0,
  9966. quantity: OfferItems[i].Quantity,
  9967. availPacks: 0,
  9968. availQty: 0,
  9969. listPrice: 0,
  9970. description: OfferItems[i].Description,
  9971. taxGroupName: "",
  9972. taxGroupId: 0,
  9973. isTaxInclusive: $("#hfIsTaxInclusive").val(),
  9974. addlDiscountPercent: OfferItems[i].Discount,
  9975. addlDiscountValue: 0,
  9976. creditNote: 0,
  9977. priceListId: 0,
  9978. batchId: 0,
  9979. unitPrice: 0,
  9980. invoiceallocations: null,
  9981. exciseInvoiceItem: null,
  9982. accountId: 0,
  9983. accountName: "",
  9984. walletId: 0,
  9985. Adjustment: 0,
  9986. TariffNo: "",
  9987. exciseAmount: 0,
  9988. discountName: "",
  9989. discountId: 0,
  9990. refNo: "",
  9991. DiscountGroupId: 0,
  9992. DiscountGroupName: '',
  9993. RefInvoiceItemId: 0,
  9994. MrpId: 0,
  9995. taxAdjustment: 0,
  9996. assesableAdjustment: 0,
  9997. inventoryTypeId: 0,
  9998. dcItemId: 0,
  9999. TotalRowAmount: 0,
  10000. maxQty: 0,
  10001. OfferItemId: ItemId,
  10002. IsFoc: true,
  10003. };
  10004. InvoiceItem.Instance().addDataRow(emptyRow, false);
  10005. }
  10006. }
  10007. }
  10008. }
  10009. });
  10010. }
  10011. TotalAdjustment() {
  10012. if ($('#chk_AutoAdjustment').is(':checked')) {
  10013. var total = $('.nettotal').text();
  10014. var splitTotal = total.split('.');
  10015. var AdjustmentValue = 0;
  10016. var splitedAdjestment = 0;
  10017. $("#txt_Adjustment").val(0);
  10018. $(".hdn_adjustment").val(0);
  10019. if (!isNaN(Number($('#txt_Adjustment').val()))) {
  10020. AdjustmentValue = Number($('#txt_Adjustment').val());
  10021. }
  10022. if (Number(splitTotal[1]) > 0) {
  10023. if (Number(splitTotal[1]) >= 50) {
  10024. splitedAdjestment = (100 - Number(splitTotal[1])) / 100;
  10025. AdjustmentValue += splitedAdjestment;
  10026. $('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2)).blur();
  10027. $(".hdn_adjustment").val($('#txt_Adjustment').val());
  10028. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(AdjustmentValue, 2));
  10029. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(total) + AdjustmentValue), 2));
  10030. }
  10031. else {
  10032. splitedAdjestment = Number(splitTotal[1]) / 100;
  10033. AdjustmentValue -= splitedAdjestment;
  10034. $('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2));
  10035. $(".hdn_adjustment").val($('#txt_Adjustment').val());
  10036. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(AdjustmentValue, 2));
  10037. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(total) + AdjustmentValue), 2));
  10038. }
  10039. }
  10040. }
  10041. else {
  10042. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($('#txt_Adjustment').val()), 2));
  10043. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number($('.nettotal').text()) + Number($('#txt_Adjustment').val())), 2));
  10044. }
  10045. }
  10046. update_discount_total() {
  10047. var item_total = Number($("#grosstotal").html()) - Number($("#totalItemDiscount").html());
  10048. var nettotal = Number($("#totalTax").text()) + Number(item_total);
  10049. var sub_dis_total = 0;
  10050. var prev_dis_total = 0;
  10051. $(".discount-row,.netdiscount-row").each(function () {
  10052. if ($(this).find(".percentage").val() != undefined) {
  10053. var ele = $(this);
  10054. var tt = prev_dis_total;
  10055. if (!isNaN(tt))
  10056. sub_dis_total += Number(tt);
  10057. var percent = ele.find(".percentage").val();
  10058. var value = ele.find(".fixedvalue").val();
  10059. var adjustment = 0;
  10060. if (percent == "")
  10061. percent = 0;
  10062. if (value == "")
  10063. value = 0;
  10064. var totaldiscount = 0;
  10065. var totalElement = $(this).find(".netdiscount-row-total");
  10066. if (totalElement.length != 0) {
  10067. totaldiscount = (Number(percent) * Number(nettotal - sub_dis_total) / 100) + Number(value) + Number(adjustment);
  10068. }
  10069. else
  10070. totaldiscount = (Number(percent) * Number(item_total - sub_dis_total) / 100) + Number(value) + Number(adjustment);
  10071. ele.find(".discount-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaldiscount, 2));
  10072. ele.find(".netdiscount-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaldiscount, 2));
  10073. prev_dis_total = totaldiscount;
  10074. }
  10075. });
  10076. InvoiceItem.Instance().update_total();
  10077. InvoiceItem.Instance().TotalAdjustment();
  10078. }
  10079. update_expense_total() {
  10080. var item_total = Number($("#grosstotal").html()) - Number($("#totalItemDiscount").html());
  10081. var nettotal = Number($("#totalTax").text()) + Number(item_total);
  10082. var sub_dis_total = 0;
  10083. var prev_dis_total = 0;
  10084. $(".expense-row").each(function () {
  10085. if ($(this).find(".exppercentage").val() != undefined) {
  10086. var ele = $(this);
  10087. var tt = prev_dis_total;
  10088. if (!isNaN(tt))
  10089. sub_dis_total += Number(tt);
  10090. var percent = ele.find(".exppercentage").val();
  10091. var value = ele.find(".expfixedvalue").val();
  10092. var adjustment = 0;
  10093. if (percent == "")
  10094. percent = 0;
  10095. if (value == "")
  10096. value = 0;
  10097. var totalexpense = (Number(percent) * Number(nettotal - sub_dis_total) / 100) + Number(value) + Number(adjustment);
  10098. ele.find(".expense-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalexpense, 2));
  10099. prev_dis_total = totalexpense;
  10100. }
  10101. });
  10102. InvoiceItem.Instance().update_total();
  10103. InvoiceItem.Instance().TotalAdjustment();
  10104. }
  10105. RefreshItemRowDetaisl(element) {
  10106. if (element.filter('.SplInvoiceItemRow').length > 0) {
  10107. Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance().update_Discount(element);
  10108. var row = InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.invoiceItemId == element.find(".hf_selectedInvoiceItemId").val());
  10109. if (row != undefined) {
  10110. row.assesableAdjustment = element.find('.hf_ItemAssesableAdjustmentVal').val();
  10111. row.TotalAmount = element.find(".hf_RowTotal").val();
  10112. }
  10113. Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance().updateQuantity();
  10114. InvoiceItem.Instance().update_total();
  10115. }
  10116. else {
  10117. InvoiceItem.Instance().update_total();
  10118. }
  10119. }
  10120. editInvItemTaxAllocs(invoiceItemId, taxGroupId, itemId, orderItemId, element) {
  10121. var prvs = InvoiceItem.Instance().invItemTaxAdjustmentList;
  10122. var obj = {
  10123. invoiceItemId: invoiceItemId,
  10124. taxGroupId: taxGroupId,
  10125. itemId: itemId,
  10126. orderItemId: orderItemId,
  10127. element: element,
  10128. };
  10129. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/components/invoices/invoiceitemtaxalloc.js", function () {
  10130. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(obj, "", Bizgaze.Apps.Transact.Components.Invoices.InvoiceItemTaxAloc.Instance(), null, Unibase.Platform.Helpers.Size.Large);
  10131. });
  10132. InvoiceItem.Instance().invItemTaxAdjustmentList = prvs;
  10133. }
  10134. GetCustomerTurnOver() {
  10135. $(".txt_tcsadjustment").val("0");
  10136. $("#chk_tcsapplied").unbind();
  10137. $(".number_tcsamount").prop("disabled", true);
  10138. $(".div_tcsadjustment").addClass("floating-label-form-group-with-value");
  10139. $("#chk_tcsapplied").change(function () {
  10140. if ($(this).prop('checked') == true && InvoiceItem.Instance().EnableTenantTcs == false && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  10141. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  10142. $("#hdnchk_tcsapplied").val("false");
  10143. $('#chk_tcsapplied').prop('checked', false);
  10144. }
  10145. else {
  10146. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  10147. $("#txt_Adjustment").val(0);
  10148. $(".hdn_adjustment").val(0);
  10149. }
  10150. if ($(this).prop('checked') == true && $(".hdn_invoicetypeid").val() == "1") {
  10151. bootbox.confirm("Confirm if sale value is > 50,00,000 for this customer.In this current Financial Year.", function (result) {
  10152. if (result) {
  10153. $("#div_tcstaxrate").removeClass("hidden");
  10154. $(".div_tcsadjustment").removeClass("hidden");
  10155. $("#div_tcsamount").removeClass("hidden");
  10156. InvoiceItem.Instance().update_total();
  10157. InvoiceItem.Instance().TotalAdjustment();
  10158. }
  10159. else {
  10160. $("#div_tcstaxrate").addClass("hidden");
  10161. $(".div_tcsadjustment").addClass("hidden");
  10162. $("#div_tcsamount").addClass("hidden");
  10163. $('#chk_tcsapplied').prop('checked', false);
  10164. $("#hdnchk_tcsapplied").val("false");
  10165. InvoiceItem.Instance().update_total();
  10166. InvoiceItem.Instance().TotalAdjustment();
  10167. }
  10168. });
  10169. }
  10170. else if ($(this).prop('checked') == true) {
  10171. $("#div_tcstaxrate").removeClass("hidden");
  10172. $(".div_tcsadjustment").removeClass("hidden");
  10173. $("#div_tcsamount").removeClass("hidden");
  10174. InvoiceItem.Instance().update_total();
  10175. InvoiceItem.Instance().TotalAdjustment();
  10176. }
  10177. else {
  10178. $("#div_tcstaxrate").addClass("hidden");
  10179. $(".div_tcsadjustment").addClass("hidden");
  10180. $("#div_tcsamount").addClass("hidden");
  10181. InvoiceItem.Instance().update_total();
  10182. InvoiceItem.Instance().TotalAdjustment();
  10183. }
  10184. }
  10185. });
  10186. $(".txt_tcsadjustment").unbind();
  10187. $(".txt_tcsadjustment").blur(function () {
  10188. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  10189. $("#txt_Adjustment").val(0);
  10190. $(".hdn_adjustment").val(0);
  10191. }
  10192. InvoiceItem.Instance().update_total();
  10193. InvoiceItem.Instance().TotalAdjustment();
  10194. });
  10195. $("#div_tcstaxrate").addClass("hidden");
  10196. $(".div_tcsadjustment").addClass("hidden");
  10197. $("#div_tcsamount").addClass("hidden");
  10198. $("#chk_tcsapplied").prop("checked", false);
  10199. $("#chk_tcsapplied").prop("disabled", false);
  10200. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getCustomerTurnOver($(".hdn_organizationid").val(), $(".hdn_invoiceid").val(), InvoiceItem.Instance().formatDate($(".date_journaldate").val()), $(".hdn_invoicetypeid").val()).then(function (response) {
  10201. if (response.result != null) {
  10202. $(".number_tcstaxrate").val(response.result.TaxRate);
  10203. if (response.result.TCSTaxCodeId != 0) {
  10204. $(".hdn_tcstaxcodeid").val(response.result.TCSTaxCodeId);
  10205. $(".hdn_tcstaxcodeaccountid").val(response.result.TCSTaxCodeAccountId);
  10206. $(".number_tcstaxrate").prop("disabled", true);
  10207. }
  10208. InvoiceItem.Instance().TurnOver = response.result.TurnOver;
  10209. InvoiceItem.Instance().ContactTcsEnable = response.result.Enable;
  10210. InvoiceItem.Instance().EnableTenantTcs = response.result.EnableTenantTcs;
  10211. InvoiceItem.Instance().PanAvailable = response.result.PanAvailable;
  10212. InvoiceItem.Instance().TaxRate = response.result.TaxRate;
  10213. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
  10214. if (InvoiceItem.Instance().ContactTcsEnable == true && InvoiceItem.Instance().EnableTenantTcs == true) {
  10215. $("#chk_tcsapplied").prop("checked", true);
  10216. $("#hdnchk_tcsapplied").val("true");
  10217. $("#div_tcstaxrate").removeClass("hidden");
  10218. $(".div_tcsadjustment").removeClass("hidden");
  10219. $("#div_tcsamount").removeClass("hidden");
  10220. $(".number_tcsamount").prop("disabled", true);
  10221. }
  10222. else if (InvoiceItem.Instance().TurnOver > 5000000 && $(".hdn_invoicetypeid").val() == "1") {
  10223. $("#chk_tcsapplied").prop("checked", true);
  10224. $("#chk_tcsapplied").prop("disabled", "disabled");
  10225. $("#hdnchk_tcsapplied").val("true");
  10226. $("#div_tcstaxrate").removeClass("hidden");
  10227. $(".div_tcsadjustment").removeClass("hidden");
  10228. $("#div_tcsamount").removeClass("hidden");
  10229. $(".number_tcsamount").prop("disabled", true);
  10230. }
  10231. }
  10232. else if ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") {
  10233. $("#chk_tcsapplied").prop("checked", false);
  10234. $("#hdnchk_tcsapplied").val("false");
  10235. $("#div_tcstaxrate").addClass("hidden");
  10236. $(".div_tcsadjustment").addClass("hidden");
  10237. $("#div_tcsamount").addClass("hidden");
  10238. }
  10239. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_RefInvoiceId').val() == 0 && $("#hf_AppSettingName").val() == "Create Return") {
  10240. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceDetails(($(".hdn_invoicetypeid").val())).then(function (res) {
  10241. if (res.result != null && res.result != "") {
  10242. InvoiceItem.Instance().TaxRate = res.result.TcsTaxRate;
  10243. $(".number_tcstaxrate").val(res.result.TcsTaxRate);
  10244. $(".hdn_tcstaxcodeid").val(response.result.TcsTaxCodeId);
  10245. if (res.result.TcsTaxCodeId != 0) {
  10246. $(".number_tcstaxrate").prop("disabled", true);
  10247. }
  10248. $(".number_tcsamount").prop("disabled", true);
  10249. }
  10250. });
  10251. }
  10252. }
  10253. });
  10254. }
  10255. bindContactName() {
  10256. Unibase.Platform.Forms.Managers.TagManager.Instance().GetTagItemsByUserId(Unibase.Platform.Membership.Infos.Identity.getCurrentUser().userId).then(function (response) {
  10257. if (response.result.length == 1) {
  10258. InvoiceItem.instance.fileCacheHelper.loadJsFile("apps/crm/lobs/managers/lobmanager.js", function () {
  10259. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobByTagGroupId(response.result[0].TagGroupId).then(function (res) {
  10260. let LobId = res.result.LobId;
  10261. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobByLobId(LobId).then(function (result) {
  10262. if (result.result != null) {
  10263. if (result.result.DefaultContactId != 0) {
  10264. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  10265. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getOrgContact(result.result.DefaultContactId).then(function (response) {
  10266. if (response.result != null) {
  10267. if (response.result.OrgContactName == null)
  10268. response.result.OrgContactName = "";
  10269. var _Name = new Option(response.result.OrgContactName, response.result.OrgContactId.toString(), false, false);
  10270. $(".txtAutoComplete_orgcontactid").append(_Name).trigger("change");
  10271. $(".hfAutoCompleteId_orgcontactid").val(response.result.OrgContactId);
  10272. InvoiceItem.Instance().LoadContactDetails();
  10273. }
  10274. });
  10275. });
  10276. }
  10277. }
  10278. });
  10279. });
  10280. });
  10281. }
  10282. });
  10283. }
  10284. GetDiscounts() {
  10285. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3")) {
  10286. let contactid = Number($(".hdn_organizationid").val());
  10287. let invoicedate = moment($('.date_journaldate').val().toString(), "DD/MM/YYYY").format("YYYY-MM-DD");
  10288. if ($(".hdn_invoicetypeid").val() == "3")
  10289. invoicedate = moment($('.date_refdate').val().toString(), "DD/MM/YYYY").format("YYYY-MM-DD");
  10290. var ItemList = [];
  10291. $(".InvoiceItems").find(".item-row").each(function () {
  10292. if (!$(this).hasClass('SplitItem')) {
  10293. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0 && Number($(this).find('.prodTotalPrice').text()) > 0) {
  10294. var Quantity = Number($(this).find(".prodQuantity").val());
  10295. let ItemId = Number($(this).find(".selectedItemId").val());
  10296. ItemList.push({
  10297. ItemId: ItemId,
  10298. Quantity: Number(Quantity),
  10299. ContactId: contactid,
  10300. InvoiceDate: invoicedate
  10301. });
  10302. }
  10303. }
  10304. });
  10305. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  10306. ItemList.push({
  10307. ItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId),
  10308. Quantity: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity),
  10309. ContactId: contactid,
  10310. InvoiceDate: invoicedate
  10311. });
  10312. }
  10313. Bizgaze.Apps.Transact.Managers.OfferManager.Instance().getdiscounts(ItemList).then(function (response) {
  10314. var data = response.result;
  10315. var InvItemId = 0;
  10316. var discription = "";
  10317. if ($(".netdiscount-row[style='pointer-events:none']").length == 0 && $(".hdn_invoicetypeid").val() == "3") {
  10318. InvoiceItem.Instance().isOfferChargeApplied = false;
  10319. if (data != null)
  10320. data.PayoutValue == 0;
  10321. }
  10322. $('.netdiscount-row').each(function () {
  10323. var invoiceitemid = $(this).find(".selectedInvoiceItemId").val();
  10324. if ((data != null && (data.PayoutValue > 0 || InvoiceItem.Instance().isOfferChargeApplied) && $(this).find('.selectedItemId').val() != undefined && Number($(this).find('.selectedItemId').val()) != 0 && data.ItemId == Number($(this).find('.selectedItemId').val())) || (InvoiceItem.Instance().isOfferChargeApplied && invoiceitemid != undefined && invoiceitemid != 0 && data.ItemId == Number($(this).find('.selectedItemId').val()))) {
  10325. $(this).remove();
  10326. if (invoiceitemid != undefined || invoiceitemid != 0) {
  10327. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  10328. InvItemId = Number(invoiceitemid);
  10329. discription = $(this).find('.discountDesc').val().toString();
  10330. }
  10331. InvoiceItem.Instance().update_total();
  10332. InvoiceItem.Instance().TotalAdjustment();
  10333. }
  10334. });
  10335. if (data != null && data.PayoutValue == 0) {
  10336. if ($(".netdiscount-row[style='pointer-events:none']").length > 0) {
  10337. var invoiceitemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedInvoiceItemId").val();
  10338. $(".netdiscount-row[style='pointer-events:none']").remove();
  10339. if (invoiceitemid != undefined || invoiceitemid != 0) {
  10340. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  10341. InvItemId = Number(invoiceitemid);
  10342. $(".hdn_isofferchargeapplied").val('false');
  10343. }
  10344. InvoiceItem.Instance().update_total();
  10345. InvoiceItem.Instance().TotalAdjustment();
  10346. }
  10347. }
  10348. if ((data != null && data.PayoutValue > 0)) {
  10349. if ($(".netdiscount-row[style='pointer-events:none']").length > 0) {
  10350. var itemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedItemId").val();
  10351. if (data.ItemId != itemid) {
  10352. var invoiceitemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedInvoiceItemId").val();
  10353. $(".netdiscount-row[style='pointer-events:none']").remove();
  10354. if (invoiceitemid != undefined || invoiceitemid != 0) {
  10355. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  10356. InvItemId = Number(invoiceitemid);
  10357. }
  10358. InvoiceItem.Instance().update_total();
  10359. InvoiceItem.Instance().TotalAdjustment();
  10360. }
  10361. }
  10362. let Index = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().deleted_invoiceItems.findIndex(x => x == InvItemId);
  10363. if (Index != -1) {
  10364. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().deleted_invoiceItems.splice(Index, 1);
  10365. }
  10366. var itemRow = {
  10367. orderItemId: 0,
  10368. invoiceItemId: InvItemId,
  10369. itemName: data.ItemName,
  10370. itemId: data.ItemId,
  10371. itemSKU: '',
  10372. unitName: "",
  10373. packSize: 0,
  10374. packCount: 0,
  10375. packs: 0,
  10376. quantity: 0,
  10377. availPacks: 0,
  10378. availQty: 0,
  10379. listPrice: 0,
  10380. description: discription,
  10381. taxGroupName: "",
  10382. taxGroupId: 0,
  10383. isTaxInclusive: $("#hf_istaxinclusive").val(),
  10384. addlDiscountPercent: 0,
  10385. addlDiscountValue: data.PayoutValue,
  10386. creditNote: 0,
  10387. priceListId: 0,
  10388. batchId: 0,
  10389. unitPrice: 0,
  10390. invoiceallocations: null,
  10391. exciseInvoiceItem: null,
  10392. accountId: 0,
  10393. accountName: "",
  10394. walletId: 0,
  10395. Adjustment: 0,
  10396. IsFoc: false,
  10397. TariffNo: "",
  10398. exciseAmount: 0,
  10399. discountName: "",
  10400. discountId: 0,
  10401. refNo: "",
  10402. DiscountGroupId: 0,
  10403. DiscountGroupName: '',
  10404. RefInvoiceItemId: 0,
  10405. MrpId: 0,
  10406. taxAdjustment: 0,
  10407. assesableAdjustment: 0,
  10408. inventoryTypeId: 5,
  10409. dcItemId: 0,
  10410. TotalRowAmount: 0,
  10411. maxQty: 0,
  10412. OfferItemId: 0
  10413. };
  10414. InvoiceItem.instance.addDataRow(itemRow, false);
  10415. }
  10416. });
  10417. }
  10418. }
  10419. GetOnInvoiceDiscountItem(element) {
  10420. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3") {
  10421. var itemid = element.find('.selectedItemId').val();
  10422. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemById(Number(itemid)).then(function (response) {
  10423. var data = response.result;
  10424. let invoiceid = $(".hdn_invoiceid").val();
  10425. if (invoiceid == undefined || invoiceid == "null")
  10426. invoiceid = 0;
  10427. if (data != null && !data.Sellable && !data.Purchasable)
  10428. element.attr("style", "pointer-events:none");
  10429. if (invoiceid == "0")
  10430. element.addClass("OnInvoiceOfferItem");
  10431. });
  10432. }
  10433. }
  10434. IsCustomerIndustrial(LobId, OrganizationId) {
  10435. var url1 = "apis/v4/bizgaze/transact/invoice/checkisenablesalespipeline/invoicetype/" + $(".hdn_invoicetypeid").val() + "/lobid/" + LobId + "/organizationid/" + OrganizationId;
  10436. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getIsEnableSalesPipeline(url1).then(function (response) {
  10437. if (response.result == false) {
  10438. $(".section_Ebs").addClass("hidden");
  10439. }
  10440. else {
  10441. $(".section_Ebs").removeClass("hidden");
  10442. }
  10443. });
  10444. }
  10445. loadChangeTaxGroupAutoComplete() {
  10446. var hfTaxgroup = $("#hdn_changetaxgroup");
  10447. AutoCompleteHelper.getHelper().Create("#change_taxgroup", hfTaxgroup, _appsettings.server_url() + "/apis/v4/bizgaze/transact/tax/taxgroupautocomplete", function (result) {
  10448. });
  10449. }
  10450. ShowOrHideEInvoiceButton() {
  10451. let instance = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance();
  10452. var installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  10453. var invoiceid = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + installedAppId + "_invoiceid").Value);
  10454. instance.fileCacheHelper.loadJsFiles(["apps/transact/managers/einvoice/einvoicemanager.js"], function () {
  10455. Bizgaze.Apps.Transact.Managers.EInvoiceManager.Instance().geteinvoicebyinvoiceid(invoiceid).then(function (res) {
  10456. if (res.result != null) {
  10457. if (res.result.EInvoiceStatusId == 2 || res.result.AckNo == null)
  10458. $(".DetailSetting_" + installedAppId + "_e-Invoice").removeClass("hidden");
  10459. else
  10460. $(".DetailSetting_" + installedAppId + "_e-Invoice").addClass("hidden");
  10461. }
  10462. });
  10463. });
  10464. }
  10465. static Instance() {
  10466. if (this.instance === undefined) {
  10467. this.instance = new InvoiceItem();
  10468. }
  10469. return this.instance;
  10470. }
  10471. }
  10472. Controls.InvoiceItem = InvoiceItem;
  10473. })(Controls = Transact.Controls || (Transact.Controls = {}));
  10474. })(Transact = Apps.Transact || (Apps.Transact = {}));
  10475. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  10476. })(Bizgaze || (Bizgaze = {}));
  10477. var Bizgaze;
  10478. (function (Bizgaze) {
  10479. let Apps;
  10480. (function (Apps) {
  10481. let Transact;
  10482. (function (Transact) {
  10483. let Controls;
  10484. (function (Controls) {
  10485. class CustomerCreditHealth extends Unibase.Platform.Core.BaseComponent {
  10486. constructor() {
  10487. super(...arguments);
  10488. this.ContainerId = "";
  10489. this.PopUpContainerId = "";
  10490. }
  10491. init(formpropertyid, prop, callback) {
  10492. var instance = this;
  10493. instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
  10494. instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
  10495. }
  10496. loadControl(containerid, prop) {
  10497. let instance = this;
  10498. instance.ContainerId = Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId();
  10499. let html = instance.getCustomerCreditHealth_html();
  10500. $("#" + containerid).html(html);
  10501. }
  10502. getCustomerCreditHealth_html() {
  10503. var html = '<div class="row"><div class=" col-sm-4" id="div_CreditLimit"><div class="card card-sm shadow-hover " id="kpi_card" style="height:auto;">' +
  10504. '<div class="card-body" ><span class="d-block font-15 font-weight-500 text-dark">' +
  10505. 'Credit Limit </span><div class="mt-10"><span class="h4 mb-10 block"><span id="span_CreditLimit" class="display-5 font-weight-400 text-dark">0</span></span></div></div></div></div>' +
  10506. '<div class=" col-sm-4" id="div_AvailLimit"><div class="card card-sm shadow-hover " id="kpi_card" style="height:auto;"><div class="card-body">' +
  10507. ' <span style=" text-transform: capitalize; " class="d-block font-15 font-weight-500 text-dark"> Avail Limit </span><div class="mt-10"><span class="h4 mb-10 block"><span id="span_AvailLimit" class="display-5 font-weight-400 text-dark">0</span>' +
  10508. '</span></div></div></div></div><div class=" col-sm-4" id="div_OverDue"><div class="card card-sm shadow-hover " id="kpi_card" style="height:auto;"><div class="card-body">' +
  10509. '<span class="d-block font-15 font-weight-500 text-dark"> Over Due </span><div class="mt-10">' +
  10510. '<span class="h4 mb-10 block text-underline"><a id="lnk_OverDue"><span id="span_OverDue" class="display-5 font-weight-400 text-dark">0</span></a></span></div></div></div></div>' +
  10511. '</div ><div class="row"><div class=" col-sm-4" id="div_Due"><div class="card card-sm shadow-hover " id="kpi_card" style="height:auto;"><div class="card-body"><span class="d-block font-15 font-weight-500 text-dark">' +
  10512. 'Due</span><div class="mt-10"><span class="h4 mb-10 block text-underline"><a id="lnk_Due"><span id="span_Due" class="display-5 font-weight-400 text-dark">0</span></a>' +
  10513. ' </span></div></div></div></div><div class=" col-sm-4" id="div_Credits"><div class="card card-sm shadow-hover " id="kpi_card" style="height:auto;"><div class="card-body">' +
  10514. '<span class="d-block font-15 font-weight-500 text-dark"> Credits </span><div class="mt-10">' +
  10515. ' <span class="h4 mb-10 block text-underline"><a id="lnk_Credits"><span id="span_Credits" class="display-5 font-weight-400 text-dark">0</span></a></span>' +
  10516. ' </div></div></div></div><div class=" col-sm-4" id="div_Clearance"><div class="card card-sm shadow-hover " id="kpi_card" style="height:auto;">' +
  10517. ' <div class="card-body"><span class="d-block font-15 font-weight-500 text-dark"> Clearance</span>' +
  10518. ' <div class="mt-10"><span class="h4 mb-10 block text-underline"><a id="lnk_Clearance"><span id="span_Clearance" class="display-5 font-weight-400 text-dark">0</span></a></span>' +
  10519. ' </div></div></div></div></div>';
  10520. return html;
  10521. }
  10522. loadControlSettings(controlsettingjson, formpropertyid) {
  10523. return null;
  10524. }
  10525. loadPropertySettings(propertysettings, formpropertyid) {
  10526. return null;
  10527. }
  10528. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  10529. return null;
  10530. }
  10531. getCreditHealth(OrgContactId, OrganizationId, Type) {
  10532. var instance = this;
  10533. instance.ContainerId = Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId();
  10534. let ContactId = Number(OrganizationId == 0 ? OrgContactId : OrganizationId);
  10535. if (ContactId == 0) {
  10536. return;
  10537. }
  10538. instance.bindKPIEvents(ContactId, Type);
  10539. instance.getCCH_KPIDetails(OrgContactId, OrganizationId, Type);
  10540. }
  10541. bindKPIEvents(ContactId, Type) {
  10542. let instance = this;
  10543. let TypeName = "Sales";
  10544. if (Type.toLowerCase().indexOf("purchase") != -1) {
  10545. TypeName = "Purchase";
  10546. }
  10547. instance.fileCacheHelper.loadJsFile("apps/transact/controls/orders/credithealth.js", function () {
  10548. $("#" + instance.ContainerId).find("#div_Due").unbind().click(function () {
  10549. Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId("Bizgaze_Platform_Analytics_Reports_Due_CCH_" + TypeName + "Orders").then(function (res) {
  10550. if (res.result != null && res.result != "") {
  10551. var filter = [];
  10552. filter.push({ "Key": "organizationid", "Value": ContactId.toString(), ExpOp: 1 });
  10553. Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_Due_CCH_" + TypeName + "Orders", null, filter, null);
  10554. }
  10555. else {
  10556. instance.getKPIPopUp("Due", "div_Due");
  10557. instance.getInvoiceDetails(ContactId, "Due");
  10558. }
  10559. });
  10560. });
  10561. $("#" + instance.ContainerId).find('#div_OverDue').unbind().click(function () {
  10562. Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId("Bizgaze_Platform_Analytics_Reports_OverDue_CCH_" + TypeName + "Orders").then(function (res) {
  10563. if (res.result != null && res.result != "") {
  10564. var filter = [];
  10565. filter.push({ "Key": "organizationid", "Value": ContactId.toString(), ExpOp: 1 });
  10566. Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_OverDue_CCH_" + TypeName + "Orders", null, filter, null);
  10567. }
  10568. else {
  10569. instance.getKPIPopUp("Over Due", "div_Due");
  10570. instance.getInvoiceDetails(ContactId, "OverDue");
  10571. }
  10572. });
  10573. });
  10574. $("#" + instance.ContainerId).find("#div_Credits").unbind().click(function () {
  10575. Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId("Bizgaze_Platform_Analytics_Reports_Credits_CCH_" + TypeName + "Orders").then(function (res) {
  10576. if (res.result != null && res.result != "") {
  10577. var filter = [];
  10578. filter.push({ "Key": "organizationid", "Value": ContactId.toString(), ExpOp: 1 });
  10579. Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_Credits_CCH_" + TypeName + "Orders", null, filter, null);
  10580. }
  10581. else {
  10582. instance.getKPIPopUp("Credits", "div_Credit");
  10583. instance.getCreditNotesDetails(ContactId);
  10584. }
  10585. });
  10586. });
  10587. $("#" + instance.ContainerId).find("#div_Clearance").unbind().click(function () {
  10588. Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId("Bizgaze_Platform_Analytics_Reports_Clearance_CCH_Orders").then(function (res) {
  10589. if (res.result != null && res.result != "") {
  10590. var filter = [];
  10591. filter.push({ "Key": "organizationid", "Value": ContactId.toString(), ExpOp: 1 });
  10592. Unibase.Platform.Analytics.Components.ReportViewer.Instance().report_ViewAllByUniqueId("Bizgaze_Platform_Analytics_Reports_Clearance_CCH_Orders", null, filter, null);
  10593. }
  10594. else {
  10595. instance.getKPIPopUp("Clearance", "div_Clearance");
  10596. instance.getPaymentDetails(ContactId);
  10597. }
  10598. });
  10599. });
  10600. });
  10601. }
  10602. getKPIPopUp(WidgetTitle, CurrentDiv) {
  10603. let instance = this;
  10604. instance.PopUpContainerId = '_modal_bizgaze_popup_' + moment().unix();
  10605. instance.navigationHelper.popup(0, instance.PopUpContainerId, Bizgaze.Apps.Transact.Orders.CreditHealth.Instance(), null, Unibase.Platform.Helpers.Size.ExtraLarge);
  10606. $("#" + instance.PopUpContainerId).find("." + CurrentDiv).removeClass("hidden");
  10607. $("#" + instance.PopUpContainerId).find(".title_widget").text(WidgetTitle);
  10608. $("#" + instance.PopUpContainerId).find("#widget_list_container").empty();
  10609. }
  10610. noData() {
  10611. let instance = this;
  10612. $("#" + instance.PopUpContainerId).find(".header_list").html('<div class="alert alert-info">There is no Data</div>');
  10613. $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text("0");
  10614. $("#" + instance.PopUpContainerId).find(".header_list").removeClass("d-none");
  10615. }
  10616. getKPIData(ReportName, OrganizationId, ResultColName, elem) {
  10617. let instance = this;
  10618. let resultData = 0;
  10619. let ReportUniqueId = "Bizgaze_Platform_Analytics_Reports_" + ReportName;
  10620. let _numberHelper = Unibase.Core.Helpers.NumberHelper.Instance();
  10621. Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportByUniqueId(ReportUniqueId).then(function (res) {
  10622. if (res.result != null && res.result != "") {
  10623. var postData = {
  10624. "ReportId": res.result.ReportId,
  10625. "page": 1,
  10626. "pageSize": 20,
  10627. "Filter": [],
  10628. "FilterId": 0,
  10629. "InputParameters": [
  10630. {
  10631. "Key": "organizationid",
  10632. "Value": OrganizationId.toString(),
  10633. "ExpOp": 1
  10634. }
  10635. ],
  10636. "SearchTerm": null,
  10637. "DateFilter": null,
  10638. "DisplayModeTypeId": 1,
  10639. "FromDate": "",
  10640. "ToDate": "",
  10641. "IsPortletWidget": false,
  10642. "IsShowAll": false,
  10643. "SortColumn": ""
  10644. };
  10645. Unibase.Platform.Analytics.Managers.ReportManager.Instance().getReportInfo(postData).then(function (report_res) {
  10646. if (report_res.result != null) {
  10647. if (report_res.result.ReportJsonData.Result.Data != null && report_res.result.ReportJsonData.Result.Data != "") {
  10648. let val = JSON.parse(report_res.result.ReportJsonData.Result.Data);
  10649. resultData = _numberHelper.roundNumber(val[0][ResultColName], 2);
  10650. $("#" + instance.ContainerId).find("#" + elem).text(resultData);
  10651. }
  10652. }
  10653. });
  10654. }
  10655. });
  10656. }
  10657. getCCH_KPIDetails(OrgContactId, OrganizationId, Type) {
  10658. let instance = this;
  10659. let TypeName = "Sales";
  10660. let CreditLimit = 0;
  10661. let AvailLimit = 0;
  10662. let OverDue = 0;
  10663. let Due = 0;
  10664. let Credits = 0;
  10665. let ClearanceAmount = 0;
  10666. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getCustomerCreditHealth(OrgContactId, OrganizationId).then(function (response) {
  10667. let data = response.result;
  10668. let _numberHelper = Unibase.Core.Helpers.NumberHelper.Instance();
  10669. if (data != "" && data != null) {
  10670. CreditLimit = _numberHelper.roundNumber(data.CreditLimit, 2);
  10671. AvailLimit = _numberHelper.roundNumber(data.AvailLimit, 2);
  10672. OverDue = _numberHelper.roundNumber(data.OverDue, 2);
  10673. Due = _numberHelper.roundNumber(data.OutStandingAmount, 2);
  10674. Credits = _numberHelper.roundNumber(data.Credits, 2);
  10675. ClearanceAmount = _numberHelper.roundNumber(data.ClearanceAmount, 2);
  10676. $("#" + instance.ContainerId).find("#span_CreditLimit").text(CreditLimit);
  10677. $("#" + instance.ContainerId).find("#span_AvailLimit").text(AvailLimit);
  10678. $("#" + instance.ContainerId).find("#span_OverDue").text(OverDue);
  10679. $("#" + instance.ContainerId).find("#span_Due").text(Due);
  10680. $("#" + instance.ContainerId).find("#span_Credits").text(Credits);
  10681. $("#" + instance.ContainerId).find("#span_Clearance").text(ClearanceAmount);
  10682. }
  10683. if (Type.toLowerCase().indexOf("purchase") != -1) {
  10684. TypeName = "Purchase";
  10685. }
  10686. instance.getKPIData("CreditLimit_CCH_OrdersKPIWidget", OrganizationId, "creditlimit", "span_CreditLimit");
  10687. instance.getKPIData("AvailLimit_CCH_OrdersKPIWidget", OrganizationId, "availlimit", "span_AvailLimit");
  10688. instance.getKPIData("OverDue_CCH_" + TypeName + "OrdersKPIWidget", OrganizationId, "overdue", "span_OverDue");
  10689. instance.getKPIData("DueAmount_CCH_" + TypeName + "OrdersKPIWidget", OrganizationId, "outstandingamount", "span_Due");
  10690. instance.getKPIData("Credits_CCH_" + TypeName + "OrdersKPIWidget", OrganizationId, "credits", "span_Credits");
  10691. instance.getKPIData("ClearanceAmount_CCH_OrdersKPIWidget", OrganizationId, "clearanceamount", "span_Clearance");
  10692. });
  10693. }
  10694. getInvoiceDetails(ContactId, DueorOverDue) {
  10695. let instance = this;
  10696. let IsOverDue = false;
  10697. if (DueorOverDue == "OverDue") {
  10698. IsOverDue = true;
  10699. }
  10700. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getPendingSalesInvoicesByContactId(ContactId, IsOverDue).then(function (response) {
  10701. var PendingInvoices = response.result;
  10702. if (PendingInvoices == "") {
  10703. instance.noData();
  10704. }
  10705. else {
  10706. var CurrentDate = new Date(), IsExpired = false, html = '';
  10707. $("#" + instance.PopUpContainerId).find("#widget_list_container").html('<li class="list-group-item list-Report-Due hidden"></li>');
  10708. for (var i = 0; i < PendingInvoices.length; i++) {
  10709. var InvoiceItem = PendingInvoices[i];
  10710. var Amount = InvoiceItem.TotalAmount;
  10711. var DueDate = new Date(InvoiceItem.DueDate);
  10712. var PaidAmount = Number(InvoiceItem.PaidAmount);
  10713. var DueAmount = Number(InvoiceItem.TotalAmount) - Number(InvoiceItem.PaidAmount);
  10714. if (DueDate < CurrentDate) {
  10715. IsExpired = true;
  10716. }
  10717. html += '<li class="list-group-item data-list-item d-none d-sm-block"><div class="row px-2 text-dark d-flex align-items-center"><div class="col-sm-2 pl-0 pr-0"><span><span class="list-item-main-title">' + InvoiceItem.InvoiceNo + '</span> (' + InvoiceItem.LobShortCode + ')</span><br /><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate(InvoiceItem.InvoiceDate) + '</span><br></div><div class="col-sm-2 pl-0 pr-0"><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(InvoiceItem.RefDate, 'DD MMM YYYY') + '</span><br><span>' + InvoiceItem.RefNo + '</span></div><div class="col-sm-2 pl-0 pr-0"><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(DueDate, 'DD MMM YYYY') + '</span><br /><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().daysFromNow(InvoiceItem.InvoiceDate) + ' Days ago</span></div><div class="col-sm-2 pl-0 pr-0 text-right">' + Amount + '</div><div class="col-sm-2 text-right pl-0 pr-0">' + PaidAmount + '</div><div class="col-sm-2 pl-0 pr-0 text-right">' + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(DueAmount, 2) + '</div></div></li><li class="data-list-item d-block d-sm-none p-1"><div class="card m-0 p-2 text-dark"><div><span class="list-item-main-title">' + InvoiceItem.InvoiceNo + '</span> (' + InvoiceItem.LobShortCode + ')</div><div>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate(InvoiceItem.InvoiceDate) + '</div><ul class="d-flex justify-content-between align-items-center"><li>Due Date/</li><li>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(DueDate, 'DD MMM YYYY') + '</li></ul><ul class="d-flex justify-content-between align-items-center"><li>Days</li><li>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().daysFromNow(InvoiceItem.InvoiceDate) + ' Days ago</li></ul><ul class="d-flex justify-content-between align-items-center"><li>Total</li><li>' + Amount + '</li></ul><ul class="d-flex justify-content-between align-items-center"><li>Paid</li><li>' + PaidAmount + '</li></ul><ul class="d-flex justify-content-between align-items-center"><li>Due</li><li>' + Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(DueAmount, 2) + '</li></ul></div></li>';
  10718. }
  10719. $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text(PendingInvoices.length);
  10720. if (DueorOverDue == "Due" || (DueorOverDue == "OverDue" && IsExpired == true)) {
  10721. $("#" + instance.PopUpContainerId).find(".list-Report-Due:last").after(html);
  10722. }
  10723. else {
  10724. instance.noData();
  10725. }
  10726. }
  10727. });
  10728. }
  10729. getPaymentDetails(ContactId) {
  10730. let instance = this;
  10731. Bizgaze.Apps.Transact.Managers.PaymentManager.Instance().getAllPendingPayments(ContactId).then(function (response) {
  10732. var PendingPayments = response.result;
  10733. if (PendingPayments == "") {
  10734. instance.noData();
  10735. }
  10736. else {
  10737. $("#" + instance.PopUpContainerId).find("#widget_list_container").html('<li class="list-group-item list-Report-Clearance hidden"></li>');
  10738. var html = '';
  10739. for (var i = 0; i < PendingPayments.length; i++) {
  10740. var PaymentItem = PendingPayments[i];
  10741. var CreatedDate = new Date(PaymentItem.CreatedDate);
  10742. var currdate = new Date();
  10743. var diff = new Date(currdate - CreatedDate);
  10744. var days = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(diff / 1000 / 60 / 60 / 24, 2);
  10745. html += '<li class="list-group-item d-none d-sm-block"><div class="row "><div class="col-sm-4 pl-2 pr-0"><span ><span class="list-item-main-title">' + PaymentItem.PaymentNo + '</span> (' + PaymentItem.RefNo + ')</span><br/><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate(PaymentItem.PaymentDate) + '</span></div><div class="col-sm-2 pl-0 pr-0"><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(PaymentItem.CreatedDate, 'DD MMM YYYY') + '</span><br><span>' + PaymentItem.ContactName + '</span></div><div class="col-sm-2 ">' + days + '</div><div class="col-sm-2 text-right">' + PaymentItem.TotalAmount + '</div><div class="col-sm-2 text-right"> ' + PaymentItem.StageName + '</div></div></li><li class="data-list-item d-block d-sm-none p-1"><div class="card p-2 text-dark m-0"><ul class="d-flex justify-content-between align-items-center"><li><div><span class="list-item-main-title">' + PaymentItem.PaymentNo + '</span> (' + PaymentItem.RefNo + ')</div></li><li>' + PaymentItem.StageName + '</li></ul><ul class="d-flex justify-content-between align-items-center"><li>Days ago</li><li>' + days + '</li></ul><ul class="d-flex justify-content-between align-items-center"><li>Total</li><li>' + PaymentItem.TotalAmount + '</li></ul></div></li>';
  10746. }
  10747. $("#" + instance.PopUpContainerId).find(".list-Report-Clearance:last").after(html);
  10748. $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text(PendingPayments.length);
  10749. }
  10750. });
  10751. }
  10752. getCreditNotesDetails(ContactId) {
  10753. var instance = this;
  10754. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getCreditNotesByContactId(ContactId).then(function (response) {
  10755. var CreditNotes = response.result;
  10756. if (CreditNotes.length != 0) {
  10757. $("#" + instance.PopUpContainerId).find("#widget_list_container").html('<li class="list-group-item list-Report-Credits hidden"></li>');
  10758. var html = '';
  10759. for (var i = 0; i < CreditNotes.length; i++) {
  10760. var CreditNoteItem = CreditNotes[i];
  10761. var ConsumedAmount = CreditNoteItem.PaidAmount;
  10762. var TotalAmount = CreditNoteItem.TotalAmount;
  10763. var RemainingCredit = Number(CreditNoteItem.TotalAmount) - Number(CreditNoteItem.PaidAmount);
  10764. var html = '<li class="list-group-item text-dark"><div class="d-none d-sm-block"><div class="row"><div class="col-sm-4"><span class="list-item-main-title">' + CreditNoteItem.InvoiceNo + '</span> <span>(' + CreditNoteItem.LobShortCode + ')</span> </br><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(CreditNoteItem.InvoiceDate, 'DD MMM YYYY') + '</span></div><div class="col-sm-2"><span>' + CreditNoteItem.RefNo + '</span><br /><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(CreditNoteItem.RefDate, 'DD MMM YYYY') + '</span></div><div class="col-sm-2 text-right">' + TotalAmount + '</div><div class="col-sm-2 text-right">' + ConsumedAmount + '</div><div class="col-sm-2 text-right">' + RemainingCredit + '</div></div></div><div class="d-block d-sm-none"><div class="card p-2 m-0"><div><span class="list-item-main-title">' + CreditNoteItem.InvoiceNo + '</span> <span>(' + CreditNoteItem.LobShortCode + ')</span> </br><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(CreditNoteItem.InvoiceDate, 'DD MMM YYYY') + '</span></div><ul class="d-flex justify-content-between align-items-center"> <li>Total</li><li>' + TotalAmount + '</li></ul><ul class="d-flex justify-content-between align-items-center"> <li>Consumed </li><li>' + ConsumedAmount + '</li></ul><ul class="d-flex justify-content-between align-items-center"> <li>Remaining</li><li>' + RemainingCredit + '</li></ul></div></div></li>';
  10765. $("#" + instance.PopUpContainerId).find(".list-Report-Credits:last").after(html);
  10766. }
  10767. }
  10768. $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text(CreditNotes.length);
  10769. if (CreditNotes.length == 0 || CreditNotes == "") {
  10770. $("#" + instance.PopUpContainerId).find(".header_list").removeClass("d-md-block").addClass("d-none");
  10771. }
  10772. instance.getAdvancePayments(ContactId, CreditNotes.length);
  10773. });
  10774. }
  10775. getAdvancePayments(ContactId, CreditsCount) {
  10776. let instance = this;
  10777. Bizgaze.Apps.Transact.Managers.PaymentManager.Instance().getAdvancePaymentsByOrgId(ContactId).then(function (response) {
  10778. var AdvancePayments = response.result;
  10779. $("#" + instance.PopUpContainerId).find("#widget_list_container").append('<div class="card card-advancePayments m-0 py-2 px-3"><div class="d-flex justify-content-between align-items-center"><div class="biz-highlight-bg-color font-16 font-weight-600" href="javascript:;"><i class="fa fa-angle-down d-none"></i><i class="fa fa-angle-right"></i><span class="ml-10 title_widget">Advance Payments</span></div><div class="d-flex align-items-center card-action-wrap"><span class="pull-right badge badge-light badge-pill badge-outline mr-10 advacepayment_Listsearch_count"></span></div></div></div><li class="list-group-item list-Report-Payments hidden"></li>');
  10780. if (AdvancePayments != "") {
  10781. var advancepaymentcount = AdvancePayments.length;
  10782. $(".advacepayment_Listsearch_count").html(advancepaymentcount);
  10783. if (AdvancePayments.length == 0 && CreditsCount == 0) {
  10784. instance.noData();
  10785. $(".card-advancePayments").addClass("d-none");
  10786. }
  10787. for (var i = 0; i < AdvancePayments.length; i++) {
  10788. var AdvancePaymentItem = AdvancePayments[i];
  10789. var ConsumedAmount = AdvancePaymentItem.AdjustedAmount;
  10790. var TotalAmount = AdvancePaymentItem.TotalAmount;
  10791. var RemainingCredit = Number(AdvancePaymentItem.TotalAmount) - Number(AdvancePaymentItem.AdjustedAmount);
  10792. var ExpTextColor = "text-info";
  10793. var html = '<li class="list-group-item"><div class="panel wrapper-xs panel-success text-dark d-none d-sm-block"><div class="row"><div class="col-sm-4"><a class="list-group-anchor"><span class="list-item-main-title ' + ExpTextColor + '">' + AdvancePaymentItem.PaymentNo + '</span></a><br><span> ' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(AdvancePaymentItem.PaymentDate, 'DD MMM YYYY') + '</span></div><div class="col-sm-2 b-r ">' + Unibase.Platform.Helpers.DateTimeHelper.Instance().daysFromNow(AdvancePaymentItem.PaymentDate) + ' days ago</div><div class="col-sm-2 b-r text-right">' + TotalAmount + '</div><div class="col-sm-2 b-r text-right">' + ConsumedAmount + '</div><div class="col-sm-2 b-r text-right">' + RemainingCredit + '</div></div></div><div class="panel wrapper-xs panel-success text-dark d-block d-sm-none"><div class="card p-2 m-0"><div><span class="list-item-main-title">' + AdvancePaymentItem.PaymentNo + '</span></br><span>' + Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDateformat(AdvancePaymentItem.PaymentDate, 'DD MMM YYYY') + '</span></div><ul class="d-flex justify-content-between align-items-center"> <li>Total</li><li>' + TotalAmount + '</li></ul><ul class="d-flex justify-content-between align-items-center"> <li>Consumed </li><li>' + ConsumedAmount + '</li></ul><ul class="d-flex justify-content-between align-items-center"> <li>Remaining</li><li>' + RemainingCredit + '</li></ul></div></div></li>';
  10794. $("#" + instance.PopUpContainerId).find(".list-Report-Payments:last").after(html);
  10795. }
  10796. $("#" + instance.PopUpContainerId).find(".span_Listsearch_count").text(CreditsCount + AdvancePayments.length);
  10797. }
  10798. else {
  10799. instance.noData();
  10800. }
  10801. });
  10802. }
  10803. static Instance() {
  10804. if (this.instance === undefined) {
  10805. this.instance = new CustomerCreditHealth();
  10806. }
  10807. return this.instance;
  10808. }
  10809. }
  10810. Controls.CustomerCreditHealth = CustomerCreditHealth;
  10811. })(Controls = Transact.Controls || (Transact.Controls = {}));
  10812. })(Transact = Apps.Transact || (Apps.Transact = {}));
  10813. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  10814. })(Bizgaze || (Bizgaze = {}));