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.

invoiceitem.component.js 416KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470
  1. var Bizgaze;
  2. (function (Bizgaze) {
  3. let Apps;
  4. (function (Apps) {
  5. let Transact;
  6. (function (Transact) {
  7. let Controls;
  8. (function (Controls) {
  9. class InvoiceItem extends Unibase.Platform.Core.BaseComponent {
  10. constructor() {
  11. super(...arguments);
  12. this.rowIndex = 0;
  13. this.itemIds = new Array();
  14. this.dcItemIds = new Array();
  15. this.SplitedInvoiceItemList = new Array();
  16. this.deleted_invoiceItems = new Array();
  17. this.invItemTaxAdjustmentList = new Array();
  18. this.container = "";
  19. this.AutoDc = false;
  20. this.OrderSettingId = 0;
  21. this.orderid = 0;
  22. this.dcid = 0;
  23. this.ClaimId = 0;
  24. this.TurnOver = 0;
  25. this.TaxRate = 0;
  26. this.ContactTcsEnable = false;
  27. this.EnableTenantTcs = false;
  28. this.PanAvailable = false;
  29. this.IswalkinCustomer = false;
  30. this.ManageInvoice = 2;
  31. this.ManageInvoiceTax = 2;
  32. this.UOMs = [];
  33. this.ChangedUOM = false;
  34. this.isOfferChargeApplied = false;
  35. }
  36. init(formpropertyid, prop, callback) {
  37. var instance = InvoiceItem.Instance();
  38. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("platform/core/helpers/numberhelper/numberhelper.js", function () {
  39. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  40. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/paymentterms/paymenttermmanager.js", function () {
  41. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/offers/offermanager.js", function () {
  42. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/compact/components/details/details.js", function () {
  43. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("platform/forms/components/formviewer/formviewer.js", function () {
  44. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("libs/parsley/parsley.min.js", function () {
  45. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  46. instance.loadControlSettings(prop.ControlJsonText, prop.FormPropertyId);
  47. instance.loadPropertySettings(prop.PropertySettings, prop.FormPropertyId);
  48. });
  49. });
  50. });
  51. });
  52. });
  53. });
  54. });
  55. });
  56. }
  57. loadControl(containerid, prop) {
  58. let instance = this;
  59. 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>';
  60. $("#" + containerid).html(html);
  61. $('.advanced-opitions').on('click', function () {
  62. $('#change_taxgroup').val(null).trigger('change');
  63. $('.advchange_taxgroup').toggleClass('hidden-element');
  64. $('.advchange_taxgroup').find('.select2-selection__placeholder span').text('Select Tax Group');
  65. });
  66. InvoiceItem.instance.container = containerid;
  67. InvoiceItem.Instance().loadChangeTaxGroupAutoComplete();
  68. }
  69. invoiceinit() {
  70. if (InvoiceItem.Instance().orderid != 0) {
  71. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  72. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorderbranchsettings(InvoiceItem.Instance().orderid).then(function (response) {
  73. if (response.result != null) {
  74. if (response.result.SettingValue == "Invoice First") {
  75. InvoiceItem.Instance().OrderSettingId = 2;
  76. }
  77. else if (response.result.SettingValue == "DC First" || response.result.SettingValue == "GRN First") {
  78. InvoiceItem.Instance().OrderSettingId = 1;
  79. }
  80. }
  81. });
  82. }
  83. $(".dropdown_istaxinclusive option[value='false']").attr('selected', 'true');
  84. $(".dropdown_paymentmethodid option[value='0']").attr('selected', 'true');
  85. $(".nettotal").remove();
  86. var VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  87. $("#" + VisibleContainerId).find(".btn_Save_Form").addClass("hidden");
  88. var nettotal = '<strong class="nettotal mt-5 mr-5">0.00</strong>';
  89. if ($('.Title').siblings('.btn-group').length > 0)
  90. $('.Title').siblings('.btn-group').prepend(nettotal);
  91. else
  92. $('.Title').after('<strong class="nettotal mt-5 mr-5 ml-auto">0.00</strong>');
  93. $('.txtAutoComplete_paymenttermid').change(function () {
  94. InvoiceItem.Instance().LoadDueDays();
  95. });
  96. $('.date_journaldate').blur(function () {
  97. InvoiceItem.Instance().LoadDueDays();
  98. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") && $("#chk_tcsapplied").val() != undefined)
  99. InvoiceItem.Instance().GetCustomerTurnOver();
  100. });
  101. $('.date_journaldate').change(function () {
  102. var invdate = $('.date_journaldate').val().toString().split('/');
  103. let todaydate = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(), "").split('/');
  104. var Invoicedate = new Date(Number(invdate[2]), Number(invdate[1]) - 1, Number(invdate[0]));
  105. var CurrentDate = new Date(Number(todaydate[2]), Number(todaydate[1]) - 1, Number(todaydate[0]));
  106. if (Invoicedate > CurrentDate) {
  107. bootbox.confirm("Are You Sure,You want to Continue with Future Invoice", function (result) {
  108. if (result) {
  109. InvoiceItem.Instance().GetAvailableWallets(Number($(".hdn_invoiceid").val()));
  110. }
  111. else {
  112. var f = new Date();
  113. $('.date_journaldate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(f, ""));
  114. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(f, "");
  115. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  116. $('.hfdate_journaldate').val(tdate);
  117. InvoiceItem.Instance().GetAvailableWallets(Number($(".hdn_invoiceid").val()));
  118. }
  119. });
  120. }
  121. else {
  122. InvoiceItem.Instance().GetAvailableWallets(Number($(".hdn_invoiceid").val()));
  123. }
  124. InvoiceItem.Instance().GetDiscounts();
  125. });
  126. $('.date_refdate').blur(function () {
  127. let refdate = $(".date_refdate").val();
  128. if (refdate == "" || refdate == null) {
  129. var f = new Date();
  130. $('.date_refdate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(f, ""));
  131. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(f, "");
  132. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  133. $('.hfdate_refdate').val(tdate);
  134. $(".divCustomProperties_refdate").children().addClass("floating-label-form-group-with-value");
  135. }
  136. });
  137. $(".section_Ebs").addClass("hidden");
  138. $(".section_Details").addClass('hidden');
  139. $(".section_ItemDetails").addClass('hidden');
  140. $(".section_Ebs").addClass('hidden');
  141. $(".section_InvoiceAmount").addClass('hidden');
  142. $(".section_Description").addClass('hidden');
  143. $(".section_BillingAndShippingDetails").addClass('hidden');
  144. $(".section_AdvancedOptions").addClass("hidden");
  145. $(".section_Description").addClass("hidden");
  146. $(".section_Wallets").addClass("hidden");
  147. $(".section_TCS").addClass("hidden");
  148. $("#div_tcstaxrate").addClass("hidden");
  149. $(".div_tcsadjustment").addClass("hidden");
  150. $("#div_tcsamount").addClass("hidden");
  151. $(".number_tcsamount").prop("disabled", true);
  152. $(".number_tdsamount").prop("disabled", true);
  153. $(".number_tdstaxrate").prop("disabled", true);
  154. $('#chk_excludefromcampaign').prop('checked', false);
  155. $(".txt_gstno").prop("disabled", true);
  156. $(".section_InvoiceAmount .card-header").first().text('Amount');
  157. $(".hrefSection_MoreOptions").click(function () {
  158. if ($(".hrefSection_MoreOptions").text() == 'Less Options') {
  159. $(".hrefSection_MoreOptions").text('More Options');
  160. $(".section_AdvancedOptions").addClass("hidden");
  161. }
  162. else if ($(".hrefSection_MoreOptions").text() == 'More Options') {
  163. $(".hrefSection_MoreOptions").text('Less Options');
  164. $(".section_AdvancedOptions").removeClass("hidden");
  165. }
  166. });
  167. if (Unibase.Platform.Membership.Infos.Identity.getCurrentUser().settings == null) {
  168. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  169. MessageHelper.Instance().showError("Please Configure Default Branch", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  170. return false;
  171. }
  172. else if (Unibase.Platform.Membership.Infos.Identity.getSetting("companyid") == null || Unibase.Platform.Membership.Infos.Identity.getSetting("companyid") == undefined) {
  173. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  174. MessageHelper.Instance().showError("Please Configure Default Branch", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  175. return false;
  176. }
  177. else {
  178. var companyId = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("companyid"));
  179. if ($(".hdn_invoicetypeid").val() != "6" && $(".hdn_invoicetypeid").val() != "7") {
  180. var Parameters = [{ "ColumnName": "companyid", "Value": companyId }];
  181. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_orgcontactid"), Parameters);
  182. }
  183. }
  184. if ($(".hdn_invoiceid").val() == 0 && InvoiceItem.Instance().orderid == 0 && InvoiceItem.Instance().dcid == 0) {
  185. $(".txtAutoComplete_orgcontactid").change(function () {
  186. var orgid = Number($(".hfAutoCompleteId_orgcontactid").val());
  187. if (orgid > 0) {
  188. if ($(".section_Details").hasClass('hidden')) {
  189. $(".section_Details").removeClass('hidden');
  190. }
  191. if ($(".section_ItemDetails").hasClass('hidden')) {
  192. $(".section_ItemDetails").removeClass('hidden');
  193. }
  194. if ($(".section_InvoiceAmount").hasClass('hidden')) {
  195. $(".section_InvoiceAmount").removeClass('hidden');
  196. }
  197. if ($(".section_Description").hasClass('hidden')) {
  198. $(".section_Description").removeClass('hidden');
  199. }
  200. if ($(".section_BillingAndShippingDetails").hasClass('hidden')) {
  201. $(".section_BillingAndShippingDetails").removeClass('hidden');
  202. }
  203. if ($(".section_Wallets").hasClass('hidden')) {
  204. $(".section_Wallets").removeClass("hidden");
  205. }
  206. if ($(".section_TCS").hasClass('hidden')) {
  207. $(".section_TCS").removeClass("hidden");
  208. }
  209. var organiztionid = $(".hfAutoCompleteId_orgcontactid").val();
  210. if (organiztionid != 0 && organiztionid != undefined && organiztionid != -1) {
  211. InvoiceItem.Instance().LoadContactDetails();
  212. }
  213. $("#btn_Save").removeClass('hidden');
  214. var VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  215. $("#" + VisibleContainerId).find(".btn_Save_Form").removeClass("hidden");
  216. }
  217. });
  218. }
  219. $('.dropdown_istaxinclusive').change(function () {
  220. var invItems = InvoiceItem.Instance().getInvoiceItems();
  221. InvoiceItem.Instance().update_total();
  222. InvoiceItem.Instance().TotalAdjustment();
  223. });
  224. if (Unibase.Platform.Membership.Infos.Identity.getCurrentUser().isAdmin == true) {
  225. InvoiceItem.Instance().ManageInvoice = 2;
  226. InvoiceItem.Instance().ManageInvoiceTax = 2;
  227. }
  228. else {
  229. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().GetInvoicePermissions(Number($(".hdn_invoicetypeid").val())).then(function (response) {
  230. if (response.result.length > 0) {
  231. for (var i = 0; i < response.result.length; i++) {
  232. if (response.result[i].SettingName == Unibase.Platform.Apps.Enums.SettingType.Manage.toString()) {
  233. InvoiceItem.Instance().ManageInvoice = response.result[i].SettingValue;
  234. InvoiceItem.Instance().ManageInvoiceTax = response.result[i].SettingValue;
  235. }
  236. }
  237. }
  238. });
  239. }
  240. if ($(".WalletItems").hasClass('show')) {
  241. $(".WalletItems").removeClass('show');
  242. }
  243. let invoiceid = $(".hdn_invoiceid").val();
  244. if (invoiceid == "0") {
  245. if (InvoiceItem.Instance().orderid != 0 || InvoiceItem.Instance().dcid != 0)
  246. InvoiceItem.Instance().getDcDetails();
  247. $('#txt_Adjustment').keypress(function (event) {
  248. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8) || (event.which == 45)) {
  249. }
  250. else {
  251. event.preventDefault();
  252. }
  253. }).on('paste', function (event) {
  254. event.preventDefault();
  255. });
  256. }
  257. else {
  258. InvoiceItem.Instance().bindEditInvoiceDetails(invoiceid);
  259. }
  260. $('#change_taxgroup').change(function () {
  261. if ($('#change_taxgroup option:selected').val() != undefined && $('#change_taxgroup option:selected').val() != 0) {
  262. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  263. InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupId = Number($('#change_taxgroup option:selected').val());
  264. Controls.Invoices.SplitItem.Instance().update_TaxPercentage($('#change_taxgroup option:selected').val());
  265. }
  266. $(".InvoiceItems").find(".item-row").each(function () {
  267. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  268. var TaxGroupId = Number($('#change_taxgroup option:selected').val());
  269. var txtTaxGroup = $(this).find(".prodTax");
  270. var hfProdTax = $(this).find(".hfProdTax");
  271. hfProdTax.val(TaxGroupId);
  272. txtTaxGroup.empty();
  273. txtTaxGroup.append(new Option($('#change_taxgroup option:selected').text(), TaxGroupId.toString(), true));
  274. if (hfProdTax.val() != '')
  275. InvoiceItem.Instance().update_tax($(this), hfProdTax.val());
  276. }
  277. });
  278. }
  279. });
  280. }
  281. addNetDiscountRow() {
  282. InvoiceItem.Instance().adddiscountrow(null, "", "", true);
  283. }
  284. getDcDetails() {
  285. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  286. var VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  287. $("#" + VisibleContainerId).find(".btn_Save_Form").removeClass("hidden");
  288. $("#btn_Save").removeClass('hidden');
  289. InvoiceItem.Instance().AutoDc = false;
  290. let url = "";
  291. if (InvoiceItem.Instance().dcid != 0) {
  292. url = 'apis/v4/bizgaze/transact/dcs/getdc/dcid/' + InvoiceItem.Instance().dcid;
  293. }
  294. else {
  295. url = "apis/v4/bizgaze/transact/orders/getorderbyorderid/id/" + InvoiceItem.Instance().orderid;
  296. }
  297. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getOrderDcDetails(url).then(function (response) {
  298. if (response.result != null) {
  299. if ($(".hdn_invoicetypeid").val() == "1")
  300. $("#div_FormName").text("Create Sales Invoice");
  301. else if ($(".hdn_invoicetypeid").val() == "2")
  302. $("#div_FormName").text("Create Purchase Invoice");
  303. if ($(".section_Details").hasClass('hidden')) {
  304. $(".section_Details").removeClass('hidden');
  305. }
  306. if ($(".section_ItemDetails").hasClass('hidden')) {
  307. $(".section_ItemDetails").removeClass('hidden');
  308. }
  309. if ($(".section_Ebs").hasClass('hidden')) {
  310. $(".section_Ebs").removeClass('hidden');
  311. }
  312. if ($(".section_InvoiceAmount").hasClass('hidden')) {
  313. $(".section_InvoiceAmount").removeClass('hidden');
  314. }
  315. if ($(".section_Description").hasClass('hidden')) {
  316. $(".section_Description").removeClass('hidden');
  317. }
  318. if ($(".section_BillingAndShippingDetails ").hasClass('hidden')) {
  319. $(".section_BillingAndShippingDetails ").removeClass('hidden');
  320. }
  321. if ($(".section_Wallets").hasClass('hidden')) {
  322. $(".section_Wallets").removeClass("hidden");
  323. }
  324. if ($(".section_TCS").hasClass('hidden')) {
  325. $(".section_TCS").removeClass("hidden");
  326. }
  327. let data = response.result;
  328. $(".txtAutoComplete_orgcontactid").empty();
  329. if (data.OrgContactId == 0) {
  330. InvoiceItem.Instance().IswalkinCustomer = true;
  331. $(".hfAutoCompleteId_orgcontactid").val(data.OrganizationId);
  332. var selectedCompany = new Option(data.OrganizationName, data.OrganizationId, true);
  333. $(".txtAutoComplete_orgcontactid").append(selectedCompany);
  334. }
  335. else {
  336. InvoiceItem.Instance().IswalkinCustomer = false;
  337. $(".hfAutoCompleteId_orgcontactid").val(data.OrgContactId);
  338. var selectedCompany = new Option(data.OrganizationName + " - " + data.OrgContactName, data.OrgContactId, true);
  339. $(".txtAutoComplete_orgcontactid").append(selectedCompany);
  340. }
  341. if (data.CurrencyId != 0) {
  342. $(".hdn_currencyid").val(data.CurrencyId);
  343. $(".hdn_conversionrate").val(data.ConversionRate);
  344. }
  345. if (data.OrganizationId != 0) {
  346. $(".hdn_organizationid").val(data.OrganizationId);
  347. $("#hfInv_OrganizationName").val(data.OrganizationName);
  348. }
  349. else {
  350. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorgcontact(data.OrgContactId).then(function (response) {
  351. var data = response.result;
  352. if (response.result != null && data.OrganizationId != 0) {
  353. $(".hdn_organizationid").val(response.result.OrganizationId);
  354. $("#hfInv_OrganizationName").val(data.OrganizationName);
  355. }
  356. });
  357. }
  358. $(".txt_gstno").val(response.result.GSTInNo);
  359. $(".txtAutoComplete_billfromaddressid").append(new Option(data.BillFromAddressName, data.BillFromAddressId, true));
  360. $(".txtAutoComplete_shipfromaddressid").append(new Option(data.ShipFromAddressName, data.ShipFromAddressId, true));
  361. if (InvoiceItem.Instance().orderid != 0 && InvoiceItem.Instance().dcid == 0) {
  362. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillingAddressName, data.BillingAddressId, true));
  363. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShippingAddressName, data.ShippingAddressId, true));
  364. }
  365. else {
  366. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillToAddressName, data.BillToAddressId, true));
  367. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShipToAddressName, data.ShipToAddressId, true));
  368. }
  369. if ((InvoiceItem.Instance().orderid != 0 || InvoiceItem.Instance().dcid != 0) && InvoiceItem.Instance().AutoDc == false) {
  370. $('.txtAutoComplete_billfromaddressid').prop('disabled', true);
  371. $('.txtAutoComplete_shipfromaddressid').prop('disabled', true);
  372. $('.txtAutoComplete_billtoaddressid').prop('disabled', true);
  373. $('.txtAutoComplete_shiptoaddressid').prop('disabled', true);
  374. }
  375. $(".txtAutoComplete_orgcontactid").prop('disabled', true);
  376. $('.hfAutoCompleteId_lobid').val(data.LobId);
  377. $('.txtAutoComplete_lobid').empty();
  378. $('.txtAutoComplete_lobid').append(new Option(data.LobName, data.LobId, true));
  379. $('.txtAutoComplete_lobid').prop('disabled', true);
  380. if (data.RefNo != "" && data.RefNo != null) {
  381. $(".txt_refno").val(data.RefNo);
  382. $(".div_refno").addClass("floating-label-form-group-with-value");
  383. }
  384. else {
  385. $(".txt_refno").val("");
  386. $(".div_refno").removeClass("floating-label-form-group-with-value");
  387. }
  388. $('.txtAutoComplete_salespersonid').append(new Option(data.SalesPersonName, data.SalesPersonId, true));
  389. $('.hfAutoCompleteId_salespersonid').val(data.SalesPersonId);
  390. if (InvoiceItem.Instance().orderid != 0 && InvoiceItem.Instance().orderid != undefined) {
  391. if (data.PaymentTermId != 0) {
  392. $('.hfAutoCompleteId_paymenttermid').val(data.PaymentTermId);
  393. $('.txtAutoComplete_paymenttermid').append(new Option(data.PaymentTermName, data.PaymentTermId, true));
  394. InvoiceItem.Instance().LoadDueDays();
  395. $(".txtAutoComplete_paymenttermid").prop('disabled', true);
  396. }
  397. $(".dropdown_paymentmethodid").val(data.PaymentMethodId);
  398. $(".dropdown_paymentmethodid").prop('disabled', true);
  399. if (data.BranchId != 0)
  400. $(".hdn_branchid").val(data.BranchId);
  401. $(".dropdown_istaxinclusive").val(data.IsTaxInclusive.toString());
  402. $(".dropdown_istaxinclusive").prop('disabled', true);
  403. }
  404. if (data.Description != null && data.Description != "")
  405. $(".divCustomProperties_systemnotes").find("textarea").val(data.Description);
  406. else
  407. $(".divCustomProperties_systemnotes").find("textarea").val("");
  408. $("#txt_AdjustmentAccountName").empty();
  409. $("#hf_AdjustmentAccountId").val("0");
  410. var Addr = $(".txtAutoComplete_billtoaddressid option:selected").val();
  411. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  412. Addr = $(".txtAutoComplete_billfromaddressid option:selected").val();
  413. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid option:selected").val(), Addr);
  414. InvoiceItem.Instance().bindAdjustmentAccount(data.LobId, Addr);
  415. InvoiceItem.Instance().getGSTNo();
  416. var Address = $(".txtAutoComplete_billtoaddressid option:selected").val();
  417. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7")
  418. Address = $(".txtAutoComplete_billfromaddressid option:selected").val();
  419. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  420. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressByContactId(Address).then(function (response) {
  421. if (response.result != null) {
  422. if (response.result.GSTNO != "" && response.result.GSTNO != null)
  423. $(".txt_gstno").val(response.result.GSTNO);
  424. }
  425. });
  426. });
  427. if ((data.OrderId == 0 || data.OrderId == undefined) && (InvoiceItem.Instance().dcid != 0 && InvoiceItem.Instance().dcid != undefined)) {
  428. InvoiceItem.Instance().bindDefaultPaymentTerm(data.OrganizationId, data.LobId);
  429. }
  430. 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) {
  431. $("#div_tcstaxrate").addClass("hidden");
  432. $(".div_tcsadjustment").addClass("hidden");
  433. $("#div_tcsamount").addClass("hidden");
  434. $(".number_tcsamount").prop("disabled", true);
  435. InvoiceItem.Instance().GetCustomerTurnOver();
  436. }
  437. InvoiceItem.Instance().GetAvailableWallets(0);
  438. InvoiceItem.Instance().loadOrderPendingItems();
  439. InvoiceItem.Instance().IsCustomerIndustrial(data.LobId, data.OrganizationId);
  440. }
  441. });
  442. });
  443. }
  444. bindSeries(lobid, branchid) {
  445. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getSeries($("#hf_FormInstalledAppId").val(), branchid, lobid).then(function (response) {
  446. if (response.result != null) {
  447. var seriesData = [];
  448. if (response.result.length > 0) {
  449. $(".txtSeriesAutoComplete_seriesid").empty();
  450. for (let s = 0; s < response.result.length; s++) {
  451. let Series = response.result[s];
  452. seriesData.push({ id: Series.SeriesId, text: Series.SeriesName, AddlData: Series.ManualNumbering });
  453. }
  454. $('.txtSeriesAutoComplete_seriesid').select2({
  455. data: seriesData,
  456. });
  457. $(".txtSeriesAutoComplete_seriesid").val(response.result[0].SeriesId).trigger("change");
  458. }
  459. else {
  460. Unibase.Platform.Series.Managers.SeriesManager.Instance().getActiveSeries(0, Number($("#hf_FormInstalledAppId").val())).then(function (response) {
  461. var data = response.result;
  462. if (data != null) {
  463. if (data.length != 0) {
  464. $(".txtSeriesAutoComplete_seriesid").empty();
  465. for (var s = 0; s < data.length; s++) {
  466. let Series = data[s];
  467. seriesData.push({ id: Series.SeriesId, text: Series.SeriesName, AddlData: Series.ManualNumbering });
  468. }
  469. $('.txtSeriesAutoComplete_seriesid').select2({
  470. data: seriesData,
  471. });
  472. $(".txtSeriesAutoComplete_seriesid").val(data[0].SeriesId).trigger("change");
  473. }
  474. }
  475. });
  476. }
  477. }
  478. else {
  479. Unibase.Platform.Series.Managers.SeriesManager.Instance().getActiveSeries(0, Number($("#hf_FormInstalledAppId").val())).then(function (response) {
  480. var data = response.result;
  481. if (data != null) {
  482. if (data.length != 0) {
  483. $(".txtSeriesAutoComplete_seriesid").empty();
  484. for (var s = 0; s < data.length; s++) {
  485. var Series = new Option(data[s].SeriesName, data[s].SeriesId.toString(), true);
  486. $(".txtSeriesAutoComplete_seriesid").append(Series);
  487. $(".txtSeriesAutoComplete_seriesid").val(data[s].SeriesId);
  488. }
  489. $(".txtSeriesAutoComplete_seriesid").val(data[0].SeriesId);
  490. }
  491. }
  492. });
  493. }
  494. });
  495. }
  496. bindAdjustmentAccount(lobid, branchid) {
  497. $('#hf_AdjustmentAccountId').val("0");
  498. $('#txt_AdjustmentAccountName').empty();
  499. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/ledgers/ledgermanager.js", function () {
  500. Bizgaze.Apps.Transact.Managers.LedgerManager.Instance().getLobLedgerSetting(lobid, branchid).then(function (response) {
  501. if (response.result != null && response.result != "") {
  502. $("#txt_AdjustmentAccountName").append(new Option(response.result.LedgerName, response.result.SettingValue1, true));
  503. $("#hf_AdjustmentAccountId").val(response.result.SettingValue1);
  504. $("#txt_AdjustmentAccountName").val(response.result.SettingValue1);
  505. }
  506. });
  507. });
  508. }
  509. bindDefaultPaymentTerm(organizationid, lobid) {
  510. $('.hfAutoCompleteId_paymenttermid').val(0);
  511. $('.txtAutoComplete_paymenttermid').empty();
  512. Bizgaze.Apps.Transact.Managers.PaymentTermManager.Instance().getPaymentTermByOrg(organizationid, lobid).then(function (response) {
  513. var paymentterm = response.result;
  514. if (paymentterm != null && paymentterm != "") {
  515. $('.hfAutoCompleteId_paymenttermid').val(paymentterm.PaymentTermId);
  516. $('.txtAutoComplete_paymenttermid').append(new Option(paymentterm.PaymentTermName, paymentterm.PaymentTermId, true));
  517. if (paymentterm.DueDays != null && paymentterm.DueDays > 0) {
  518. var from = $('.date_journaldate').val().toString().split("/");
  519. var f = new Date(Number(from[2]), Number(from[1]) - 1, Number(from[0]));
  520. var currentdate = f.setDate(f.getDate() + paymentterm.DueDays);
  521. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(currentdate, ""));
  522. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(currentdate), "");
  523. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  524. $('.hfdate_duedate').val(tdate);
  525. }
  526. }
  527. });
  528. }
  529. LoadContactDetails() {
  530. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorganization($(".hfAutoCompleteId_orgcontactid").val()).then(function (response) {
  531. if (response.result != null && response.result != "") {
  532. if (response.result.CurrencyId != 0) {
  533. $(".hdn_currencyid").val(response.result.CurrencyId);
  534. $(".hdn_conversionrate").val(response.result.ConversionRate);
  535. }
  536. if (response.result.OrganizationTypeId == 1)
  537. InvoiceItem.Instance().IswalkinCustomer = false;
  538. else
  539. InvoiceItem.Instance().IswalkinCustomer = true;
  540. InvoiceItem.Instance().LoadSpocDetails($(".hfAutoCompleteId_orgcontactid").val());
  541. }
  542. else {
  543. InvoiceItem.Instance().IswalkinCustomer = false;
  544. InvoiceItem.Instance().LoadSpocDetails($(".hfAutoCompleteId_orgcontactid").val());
  545. }
  546. });
  547. }
  548. LoadSpocDetails(contactid) {
  549. if ($('.hdn_invoicetypeid').val() == "1" || $('.hdn_invoicetypeid').val() == "6" || $('.hdn_invoicetypeid').val() == "4") {
  550. $('.txtAutoComplete_billtoaddressid').empty();
  551. $('.txtAutoComplete_shiptoaddressid').empty();
  552. }
  553. else {
  554. $('.txtAutoComplete_billfromaddressid').empty();
  555. $('.txtAutoComplete_shipfromaddressid').empty();
  556. }
  557. if ($(".hdn_invoiceid").val() == "0") {
  558. $(".txtAutoComplete_LobId").empty();
  559. $(".hfAutoCompleteId_LobId").empty();
  560. }
  561. $(".txtAutoComplete_salespersonid").empty();
  562. $(".hfAutoCompleteId_salespersoid").empty();
  563. if (InvoiceItem.Instance().IswalkinCustomer == true) {
  564. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorganization(contactid).then(function (response) {
  565. if (response.result != null) {
  566. $(".hdn_organizationid").val(response.result.OrganizationId);
  567. $("#hfInv_OrganizationName").val(response.result.OrganizationName);
  568. 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) {
  569. InvoiceItem.Instance().GetCustomerTurnOver();
  570. }
  571. $.when(InvoiceItem.Instance().loadAddressAutoCompletes(response.result.OrganizationId)).then(function () {
  572. InvoiceItem.Instance().BindAddressDetails(response.result.OrganizationId);
  573. InvoiceItem.Instance().GetAvailableWallets(0);
  574. });
  575. }
  576. });
  577. }
  578. else {
  579. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getorgcontact(contactid).then(function (response) {
  580. var data = response.result;
  581. if (response.result != null && data.OrganizationId != 0) {
  582. $(".hdn_organizationid").val(response.result.OrganizationId);
  583. $("#hfInv_OrganizationName").val(data.OrganizationName);
  584. 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) {
  585. InvoiceItem.Instance().GetCustomerTurnOver();
  586. }
  587. $.when(InvoiceItem.Instance().loadAddressAutoCompletes(response.result.OrganizationId)).then(function () {
  588. InvoiceItem.Instance().BindAddressDetails(response.result.OrganizationId);
  589. InvoiceItem.Instance().GetAvailableWallets(0);
  590. });
  591. }
  592. });
  593. }
  594. }
  595. GetJournalAlloc(invoiceId) {
  596. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getJournalAllocs(invoiceId).then(function (response) {
  597. if (response.result.length > 0)
  598. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  599. });
  600. }
  601. formatDate(date) {
  602. var datearray = date.split("/");
  603. var newdate = datearray[1] + '/' + datearray[0] + '/' + datearray[2];
  604. var d = new Date(newdate), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear();
  605. if (month.length < 2)
  606. month = '0' + month;
  607. if (month.length < 2)
  608. month = '0' + month;
  609. if (day.length < 2)
  610. day = '0' + day;
  611. return [year, month, day].join('-');
  612. }
  613. GetAvailableWallets(invoiceid) {
  614. var ContactId = $(".hdn_organizationid").val();
  615. var invoiceId = 0;
  616. if (invoiceid != 0 && $('#hfInv_IsRetun').val() != "1") {
  617. invoiceId = Number($(".hdn_invoiceid").val());
  618. }
  619. if (invoiceId != 0)
  620. InvoiceItem.Instance().GetJournalAlloc(invoiceId);
  621. var invoicedate = $('.date_journaldate').val();
  622. var invdate = InvoiceItem.Instance().formatDate(invoicedate);
  623. var lobId = $(".txtAutoComplete_lobid").val();
  624. if (lobId == null || lobId == undefined)
  625. lobId = 0;
  626. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getJournalWallets(invdate, invoiceId, ContactId, Number($(".hdn_invoicetypeid").val()), lobId).then(function (response) {
  627. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/payments/wallet.component.js", function () {
  628. if (response.result != null) {
  629. Bizgaze.Apps.Transact.Controls.Wallet.Instance().loadInvoiceWallets(response.result);
  630. }
  631. });
  632. });
  633. }
  634. BindAddressDetails(orgid) {
  635. let branchid = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  636. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getbranche(branchid).then(function (responce) {
  637. if (responce.result != null) {
  638. if (responce.result.DefaultWarehouseId != 0)
  639. var ShipTo = new Option(responce.result.DefaultWarehouseName, responce.result.DefaultWarehouseId, true);
  640. else
  641. var ShipTo = new Option(responce.result.BranchName, responce.result.BranchId, true);
  642. var BillTo = new Option(responce.result.BranchName, responce.result.BranchId, true);
  643. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  644. $(".txtAutoComplete_shiptoaddressid").append(ShipTo);
  645. $(".txtAutoComplete_billtoaddressid").append(BillTo);
  646. $(".txtAutoComplete_billtoaddressid").change(function () {
  647. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid").val(), $(".txtAutoComplete_billtoaddressid").val());
  648. InvoiceItem.Instance().bindAdjustmentAccount($(".txtAutoComplete_lobid").val(), responce.result.BranchId);
  649. });
  650. }
  651. else {
  652. $(".txtAutoComplete_shipfromaddressid").append(ShipTo);
  653. $(".txtAutoComplete_billfromaddressid").append(BillTo);
  654. $(".txtAutoComplete_billfromaddressid").change(function () {
  655. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid").val(), $(".txtAutoComplete_billfromaddressid").val());
  656. InvoiceItem.Instance().bindAdjustmentAccount($(".txtAutoComplete_lobid").val(), responce.result.BranchId);
  657. });
  658. }
  659. }
  660. });
  661. this.fileCacheHelper.loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  662. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressByContactId(orgid).then(function (response) {
  663. if (response.result != null && response.result != "") {
  664. var ShipTo = new Option(response.result.AddressName, response.result.ContactAddressId, true);
  665. var BillTo = new Option(response.result.AddressName, response.result.ContactAddressId, true);
  666. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4") {
  667. $(".txtAutoComplete_shiptoaddressid").append(ShipTo);
  668. $(".txtAutoComplete_billtoaddressid").append(BillTo);
  669. $(".txtAutoComplete_billtoaddressid").change(function () {
  670. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  671. InvoiceItem.Instance().BindLoB();
  672. });
  673. });
  674. InvoiceItem.Instance().getGSTNo();
  675. }
  676. else {
  677. $(".txtAutoComplete_shipfromaddressid").append(ShipTo);
  678. $(".txtAutoComplete_billfromaddressid").append(BillTo);
  679. $(".txtAutoComplete_billfromaddressid").change(function () {
  680. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  681. InvoiceItem.Instance().BindLoB();
  682. });
  683. });
  684. InvoiceItem.Instance().getGSTNo();
  685. }
  686. if (response.result.GSTNO != "" && response.result.GSTNO != null)
  687. $(".txt_gstno").val(response.result.GSTNO);
  688. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  689. InvoiceItem.Instance().BindLoB();
  690. });
  691. }
  692. else {
  693. MessageHelper.Instance().showError("Please assign billing address and shipping address", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  694. }
  695. });
  696. });
  697. }
  698. getGSTNo() {
  699. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  700. var gstno = $(".txt_gstno").val();
  701. if (Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.length > 0 && Number($(".hdn_invoiceid").val()) != 0) {
  702. gstno = Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + InstalledAppId + "_gstno").Value;
  703. }
  704. $(".txt_gstno").parent().addClass("floating-label-form-group-with-value");
  705. if (gstno != null && gstno != "") {
  706. $(".txt_gstno").val(gstno);
  707. }
  708. else
  709. $(".txt_gstno").val("GSTIN not Assigned");
  710. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4") {
  711. $(".txtAutoComplete_billtoaddressid").change(function () {
  712. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressById(Number($(".txtAutoComplete_billtoaddressid").val())).then(function (ress) {
  713. if (ress.result != null) {
  714. if (ress.result.GSTNO != "" && ress.result.GSTNO != null)
  715. $(".txt_gstno").val(ress.result.GSTNO);
  716. }
  717. });
  718. });
  719. }
  720. else {
  721. $(".txtAutoComplete_billfromaddressid").change(function () {
  722. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getAddressById(Number($(".txtAutoComplete_billfromaddressid").val())).then(function (ress) {
  723. if (ress.result != null) {
  724. if (ress.result.GSTNO != "" && ress.result.GSTNO != null)
  725. $(".txt_gstno").val(ress.result.GSTNO);
  726. }
  727. });
  728. });
  729. }
  730. }
  731. loadLobAndSp() {
  732. var AddressId = $(".txtAutoComplete_billfromaddressid option:selected").val();
  733. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "4")
  734. AddressId = $(".txtAutoComplete_billtoaddressid option:selected").val();
  735. var lobParameters = [{ "ColumnName": "contactaddressid", "Value": AddressId, }];
  736. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_lobid"), lobParameters);
  737. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/orders/ordermanager.js", function () {
  738. var SpParameters = [{ "ColumnName": "contactaddressid", "Value": AddressId, }];
  739. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_salespersonid"), null);
  740. });
  741. }
  742. BindLoB() {
  743. $(".txtAutoComplete_lobid").empty();
  744. $('#hf_AdjustmentAccountId').val("0");
  745. $('#txt_AdjustmentAccountName').empty();
  746. if ($(".hdn_invoiceid").val() == "0") {
  747. $(".InvoiceItems").find(".item-addedrow").remove();
  748. InvoiceItem.Instance().SplitedInvoiceItemList = new Array();
  749. InvoiceItem.Instance().itemIds = [0];
  750. InvoiceItem.Instance().dcItemIds = [0];
  751. $("#txt_Adjustment").val("0");
  752. $("#span_Adjustment").text("0");
  753. InvoiceItem.Instance().update_total();
  754. InvoiceItem.Instance().TotalAdjustment();
  755. }
  756. var AddressId = $(".txtAutoComplete_billfromaddressid option:selected").val();
  757. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  758. AddressId = $(".txtAutoComplete_billtoaddressid option:selected").val();
  759. this.fileCacheHelper.loadJsFile("apps/crm/lobs/managers/lobmanager.js", function () {
  760. if (AddressId == undefined) {
  761. AddressId = 0;
  762. }
  763. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobsByAddressId(Number(AddressId)).then(function (response) {
  764. if (response.message != '') {
  765. Unibase.Platform.Forms.Components.FormViewer.Instance().showError(response.message);
  766. }
  767. if (response.result != "" && response.result != null) {
  768. if (response.result.length == 1) {
  769. var LoB = new Option(response.result[0].LobName, response.result[0].LobId, true);
  770. $(".txtAutoComplete_lobid").append(LoB);
  771. $(".txtAutoComplete_lobid").val(response.result[0].LobId);
  772. InvoiceItem.Instance().BindSalesPerson(AddressId);
  773. InvoiceItem.Instance().bindDefaultPaymentTerm($(".hdn_organizationid").val(), response.result[0].LobId);
  774. var Addr = $(".txtAutoComplete_billtoaddressid option:selected").val();
  775. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  776. Addr = $(".txtAutoComplete_billfromaddressid option:selected").val();
  777. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid option:selected").val(), Addr);
  778. InvoiceItem.Instance().bindAdjustmentAccount(response.result[0].LobId, Addr);
  779. }
  780. }
  781. });
  782. });
  783. $(".txtAutoComplete_lobid").change(function () {
  784. InvoiceItem.Instance().bindDefaultPaymentTerm($(".hdn_organizationid").val(), $(".txtAutoComplete_lobid option:selected").val());
  785. var Address = $(".txtAutoComplete_billtoaddressid option:selected").val();
  786. var Billto = $(".txtAutoComplete_billfromaddressid option:selected").val();
  787. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6") {
  788. Address = $(".txtAutoComplete_billfromaddressid option:selected").val();
  789. Billto = $(".txtAutoComplete_billtoaddressid option:selected").val();
  790. }
  791. InvoiceItem.Instance().BindSalesPerson(Billto);
  792. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid option:selected").val(), Address);
  793. InvoiceItem.Instance().bindAdjustmentAccount($(".txtAutoComplete_lobid option:selected").val(), Address);
  794. $(".InvoiceItems").find(".item-addedrow").remove();
  795. InvoiceItem.Instance().SplitedInvoiceItemList = new Array();
  796. InvoiceItem.Instance().itemIds = [0];
  797. InvoiceItem.Instance().dcItemIds = [0];
  798. $("#txt_Adjustment").val("0");
  799. InvoiceItem.Instance().update_total();
  800. InvoiceItem.Instance().TotalAdjustment();
  801. InvoiceItem.Instance().GetAvailableWallets(0);
  802. });
  803. }
  804. BindSalesPerson(AddressId) {
  805. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  806. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getManagerDetails(Number($(".txtAutoComplete_lobid option:selected").val()), AddressId).then(function (response) {
  807. if (response.result != null) {
  808. var SalesPerson = new Option(response.result.ManagerName, response.result.EmployeeId, true);
  809. $(".txtAutoComplete_salespersonid").empty();
  810. $(".txtAutoComplete_salespersonid").append(SalesPerson);
  811. $(".txtAutoComplete_salespersonid").val(response.result.EmployeeId);
  812. }
  813. else {
  814. $(".txtAutoComplete_salespersonid").empty();
  815. $(".txtAutoComplete_salespersonid").val(0);
  816. $(".txtAutoComplete_salespersonid").text("");
  817. }
  818. });
  819. });
  820. }
  821. LoadDueDays() {
  822. if (InvoiceItem.Instance().dcid != 0 && InvoiceItem.Instance().AutoDc == false && InvoiceItem.Instance().OrderSettingId != 2) {
  823. var invdate = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatServerDate($('.date_journaldate').val());
  824. if (InvoiceItem.Instance().DcDate != undefined) {
  825. var date = InvoiceItem.Instance().DcDate.toString();
  826. var dcdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  827. if (invdate < dcdate) {
  828. var dctext = "DC";
  829. if ($('.hdn_invoicetypeid').val() == "2")
  830. dctext = "GRN";
  831. MessageHelper.Instance().showError("Invoice Date should not be less than " + dctext + " Date", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  832. }
  833. }
  834. }
  835. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/paymentterms/paymenttermmanager.js", function () {
  836. Bizgaze.Apps.Transact.Managers.PaymentTermManager.Instance().getPaymentTerm(Number($('.hfAutoCompleteId_paymenttermid').val())).then(function (result) {
  837. if (result.result != null) {
  838. if (result.result.DueDays > 0) {
  839. if ($('.date_journaldate').val() == "") {
  840. let todaydate = Unibase.Platform.Helpers.DateTimeHelper.Instance().currentDate();
  841. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""));
  842. $('.hfdate_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""));
  843. }
  844. else {
  845. var from = $('.date_journaldate').val().toString().split('/');
  846. var f = new Date(Number(from[2]), Number(from[1]) - 1, Number(from[0]));
  847. var currentdate = f.setDate(f.getDate() + result.result.DueDays);
  848. var currentdate1 = f.setDate(f.getDate() + result.result.DueDays + 1);
  849. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(currentdate), ""));
  850. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(currentdate), "");
  851. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  852. $('.hfdate_duedate').val(tdate);
  853. }
  854. }
  855. }
  856. });
  857. });
  858. }
  859. loadAddressAutoCompletes(organizationid) {
  860. var ToAddressParameters = [{ "ColumnName": "contactid", "Value": organizationid, }];
  861. let invoicetypeid = $(".hdn_invoicetypeid").val();
  862. if (invoicetypeid == "1" || invoicetypeid == "4" || invoicetypeid == "6") {
  863. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billtoaddressid"), ToAddressParameters);
  864. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shiptoaddressid"), ToAddressParameters);
  865. $(".txtAutoComplete_billtoaddressid").change(function () {
  866. if (Number($(".hdn_invoiceid").val()) == 0) {
  867. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  868. InvoiceItem.Instance().BindLoB();
  869. });
  870. }
  871. });
  872. }
  873. else {
  874. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billfromaddressid"), ToAddressParameters);
  875. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shipfromaddressid"), ToAddressParameters);
  876. $(".txtAutoComplete_billfromaddressid").change(function () {
  877. $.when(InvoiceItem.Instance().loadLobAndSp()).then(function () {
  878. InvoiceItem.Instance().BindLoB();
  879. });
  880. });
  881. }
  882. var FromAddressParameters = [{ "ColumnName": "companyid", "Value": Number(Unibase.Platform.Membership.Infos.Identity.getSetting("companyid")) }];
  883. if (invoicetypeid == "1" || invoicetypeid == "4" || invoicetypeid == "6") {
  884. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billfromaddressid"), FromAddressParameters);
  885. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shipfromaddressid"), FromAddressParameters);
  886. }
  887. else {
  888. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_billtoaddressid"), FromAddressParameters);
  889. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_shiptoaddressid"), FromAddressParameters);
  890. }
  891. }
  892. loadControlSettings(controlsettingjson, formpropertyid) {
  893. var instance = InvoiceItem.Instance();
  894. $("#btnInvoiceItem").off().click(function () {
  895. let lobid = $(".hfAutoCompleteId_lobid").val();
  896. if (lobid == undefined || lobid == "" || lobid == "0") {
  897. MessageHelper.Instance().showError("Please Select LoB", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  898. return false;
  899. }
  900. else
  901. InvoiceItem.instance.addRow();
  902. });
  903. $("#btndiscountItem").off().click(function () {
  904. InvoiceItem.Instance().adddiscountrow(null, "", "", false);
  905. });
  906. instance.itemIds = new Array();
  907. instance.dcItemIds = new Array();
  908. instance.itemIds.push(0);
  909. instance.dcItemIds.push(0);
  910. instance.SplitedInvoiceItemList = new Array();
  911. instance.deleted_invoiceItems = new Array();
  912. instance.invItemTaxAdjustmentList = new Array();
  913. instance.AutoDc = false;
  914. instance.OrderSettingId = 0;
  915. instance.orderid = 0;
  916. instance.dcid = 0;
  917. instance.IswalkinCustomer = false;
  918. $('.inv_hdnfiels').empty();
  919. var d = "<div class='inv_hdnfiels'></div>";
  920. $(".section_CompanyDetails").prepend(d);
  921. var hiddenfileds = "<input type='hidden' id='hfInv_OrganizationName' value=''/>" +
  922. "<input type='hidden' id='hfInv_IsRetun' value='0'/>" +
  923. "<input type='hidden' id='hfInv_wallet' value='false' />";
  924. $('.inv_hdnfiels').append(hiddenfileds);
  925. $(".hdn_branchid").val(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  926. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  927. for (let obj of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) {
  928. if (obj.Key === "hf_" + InstalledAppId + "_orderid") {
  929. InvoiceItem.Instance().orderid = Number(Number(obj.Value));
  930. $(".hdn_orderid").val(Number(obj.Value));
  931. if (Number(obj.Value) != 0) {
  932. for (let ob of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) {
  933. if (ob.Key === "hf_" + InstalledAppId + "_branchid")
  934. $(".hdn_branchid").val(ob.Value);
  935. }
  936. }
  937. }
  938. if (obj.Key === "hf_" + InstalledAppId + "_dcid") {
  939. InvoiceItem.instance.dcid = Number(obj.Value);
  940. $(".hdn_dcid").val(Number(obj.Value));
  941. }
  942. if (obj.Key === "hf_" + InstalledAppId + "_claimid") {
  943. InvoiceItem.instance.ClaimId = Number(obj.Value);
  944. }
  945. if (obj.Key === "hf_" + InstalledAppId + "_dcdate") {
  946. InvoiceItem.instance.DcDate = obj.Value;
  947. }
  948. }
  949. if ((InvoiceItem.instance.dcid == 0 || InvoiceItem.instance.dcid == undefined) && (InvoiceItem.instance.dcid == 0 || InvoiceItem.instance.dcid == undefined)) {
  950. instance.AutoDc = true;
  951. }
  952. InvoiceItem.Instance().invoiceinit();
  953. $("#txt_taxAajustment").blur(function () {
  954. InvoiceItem.Instance().update_total();
  955. InvoiceItem.Instance().TotalAdjustment();
  956. });
  957. $("#txt_assessableadjustment").blur(function () {
  958. InvoiceItem.Instance().update_total();
  959. InvoiceItem.Instance().TotalAdjustment();
  960. });
  961. $(document).ready(function (e) {
  962. if (Number($("#hf_pk_value").val()) != 0 && $("#chk_tdsapplied").is(":checked")) {
  963. $(".divCustomProperties_tdstaxcodeid").removeClass('hidden');
  964. $(".divCustomProperties_tdstaxrate").removeClass('hidden');
  965. $(".divCustomProperties_tdsamount").removeClass('hidden');
  966. }
  967. else {
  968. $(".divCustomProperties_tdstaxcodeid").addClass('hidden');
  969. $(".divCustomProperties_tdstaxrate").addClass('hidden');
  970. $(".divCustomProperties_tdsamount").addClass('hidden');
  971. }
  972. $("#chk_tdsapplied").removeAttr("onclick");
  973. $("#chk_tdsapplied").change(function () {
  974. if ($(this).prop('checked') == false) {
  975. $(".txtAutoComplete_tdstaxcodeid").val(0);
  976. $(".txtAutoComplete_tdstaxcodeid").text("");
  977. $(".number_tdstaxrate").val(0);
  978. $(".divCustomProperties_tdstaxcodeid").addClass('hidden');
  979. $(".divCustomProperties_tdstaxrate").addClass('hidden');
  980. $(".divCustomProperties_tdsamount").addClass('hidden');
  981. $("#chk_tcsapplied").removeAttr("disabled");
  982. $("#hdnchk_tdsapplied").val("false");
  983. }
  984. else {
  985. $("#div_tcstaxrate").addClass("hidden");
  986. $(".div_tcsadjustment").addClass("hidden");
  987. $("#div_tcsamount").addClass("hidden");
  988. $('#chk_tcsapplied').prop('checked', false);
  989. $('#chk_tcsapplied').attr('disabled', "true");
  990. $(".divCustomProperties_tdstaxcodeid").removeClass('hidden');
  991. $(".divCustomProperties_tdstaxrate").removeClass('hidden');
  992. $(".divCustomProperties_tdsamount").removeClass('hidden');
  993. $("#chk_tcsapplied").attr("disabled");
  994. $("#hdnchk_tdsapplied").val("true");
  995. }
  996. InvoiceItem.Instance().update_total();
  997. });
  998. $(".txtAutoComplete_tdstaxcodeid").change(function () {
  999. $(".number_tdstaxrate").val(Number($(".txtAutoComplete_tdstaxcodeid").attr('data-addldata')));
  1000. InvoiceItem.Instance().update_total();
  1001. });
  1002. });
  1003. }
  1004. loadPropertySettings(propertysettings, formpropertyid) {
  1005. }
  1006. bindEditFormDetails(formpropertyid, propval, DocPropertyName) {
  1007. }
  1008. bindEditInvoiceDetails(invoiceid) {
  1009. var VisibleContainerId = Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds[Unibase.Platform.Helpers.NavigationHelper.ModalContainerIds.length - 1];
  1010. $("#" + VisibleContainerId).find(".btn_Save_Form").removeClass("hidden");
  1011. if ($('.hdn_invoicetypeid').val() == "1" && $("#hf_AppSettingName").val() == "Create Return") {
  1012. $('#hfInv_IsRetun').val(1);
  1013. $('.hdn_invoicetypeid').val("3");
  1014. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  1015. $("#div_FormName").text("Create Sales Return");
  1016. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  1017. $(".hdn_journalno").val(0);
  1018. }
  1019. else if ($('.hdn_invoicetypeid').val() == "2" && $("#hf_AppSettingName").val() == "Create Return") {
  1020. $('#hfInv_IsRetun').val(1);
  1021. $('.hdn_invoicetypeid').val("4");
  1022. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  1023. $("#div_FormName").text("Create Purchase Return");
  1024. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  1025. $(".hdn_journalno").val(0);
  1026. }
  1027. let invoicetypeid = $('.hdn_invoicetypeid').val();
  1028. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/invoicemanager.js", function () {
  1029. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceDetails(invoiceid).then(function (result) {
  1030. var data = result.result;
  1031. var companyId = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("companyid"));
  1032. var Parameters = [];
  1033. if ($(".hdn_invoicetypeid").val() != "6" && $(".hdn_invoicetypeid").val() != "7")
  1034. Parameters = [{ "ColumnName": "companyid", "Value": companyId }];
  1035. Unibase.Forms.Controls.AutoComplete.Instance().LoadAutoComplete($(".txtAutoComplete_orgcontactid"), Parameters);
  1036. InvoiceItem.Instance().AutoDc = data.AutoDc;
  1037. if (data.OrgContactId == 0) {
  1038. InvoiceItem.Instance().IswalkinCustomer = true;
  1039. $(".hfAutoCompleteId_orgcontactid").val(data.OrganizationId);
  1040. var selectedCompany = new Option(data.OrganizationName, data.OrganizationId, true);
  1041. }
  1042. else {
  1043. InvoiceItem.Instance().IswalkinCustomer = false;
  1044. if (data.OrgContactName == null)
  1045. data.OrgContactName = "";
  1046. $(".hfAutoCompleteId_orgcontactid").val(data.OrgContactId);
  1047. var selectedCompany = new Option(data.OrganizationName + " - " + data.OrgContactName, data.OrgContactId, true);
  1048. }
  1049. $(".txtAutoComplete_orgcontactid").empty();
  1050. $(".txtAutoComplete_orgcontactid").append(selectedCompany);
  1051. if ($(".section_Details").hasClass('hidden')) {
  1052. $(".section_Details").removeClass('hidden');
  1053. }
  1054. if ($(".section_ItemDetails").hasClass('hidden')) {
  1055. $(".section_ItemDetails").removeClass('hidden');
  1056. }
  1057. if ($(".section_Ebs").hasClass('hidden')) {
  1058. $(".section_Ebs").removeClass('hidden');
  1059. }
  1060. if ($(".section_InvoiceAmount").hasClass('hidden')) {
  1061. $(".section_InvoiceAmount").removeClass('hidden');
  1062. }
  1063. if ($(".section_Description").hasClass('hidden')) {
  1064. $(".section_Description").removeClass('hidden');
  1065. }
  1066. if ($(".section_BillingAndShippingDetails").hasClass('hidden')) {
  1067. $(".section_BillingAndShippingDetails").removeClass('hidden');
  1068. }
  1069. if ($(".section_Wallets").hasClass('hidden')) {
  1070. $(".section_Wallets").removeClass("hidden");
  1071. }
  1072. if ($(".section_TCS").hasClass('hidden')) {
  1073. $(".section_TCS").removeClass("hidden");
  1074. }
  1075. $("#btn_Save").removeClass('hidden');
  1076. $(".txtAutoComplete_lobid").prop("disabled", true);
  1077. $(".txtAutoComplete_orgcontactid").prop("disabled", true);
  1078. if ($('#hfInv_IsRetun').val() == "1" && ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  1079. let todaydate = Unibase.Platform.Helpers.DateTimeHelper.Instance().currentDate();
  1080. $('.date_journaldate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""));
  1081. var tdate = moment(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""), "DD/MM/YYYY").format("YYYY/MM/DD");
  1082. $('.hfdate_journaldate').val(tdate);
  1083. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(todaydate), ""));
  1084. $('.hfdate_duedate').val(tdate);
  1085. InvoiceItem.Instance().LoadDueDays();
  1086. }
  1087. else {
  1088. $('.date_journaldate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.InvoiceDate, ""));
  1089. let date = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.InvoiceDate), "");
  1090. var tdate = moment(date, "DD/MM/YYYY").format("YYYY/MM/DD");
  1091. $('.hfdate_journaldate').val(tdate);
  1092. $('.date_duedate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.DueDate, ""));
  1093. var date1 = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.DueDate), "");
  1094. tdate = moment(date1, "DD/MM/YYYY").format("YYYY/MM/DD");
  1095. $('.hfdate_duedate').val(tdate);
  1096. }
  1097. $('.date_refdate').val(Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(data.RefDate, ""));
  1098. date1 = Unibase.Platform.Helpers.DateTimeHelper.Instance().formatLocalDate1(new Date(data.RefDate), "");
  1099. tdate = moment(date1, "DD/MM/YYYY").format("YYYY/MM/DD");
  1100. $('.hfdate_refdate').val(tdate);
  1101. $.when(Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().loadAddressAutoCompletes(data.OrganizationId)).then(function (response) {
  1102. $(".txtAutoComplete_billfromaddressid").empty();
  1103. $(".txtAutoComplete_billtoaddressid").empty();
  1104. $(".txtAutoComplete_shiptoaddressid").empty();
  1105. $(".txtAutoComplete_shipfromaddressid").empty();
  1106. if ($('.hdn_invoicetypeid').val() == "1" || $('.hdn_invoicetypeid').val() == "4" || $('.hdn_invoicetypeid').val() == "6") {
  1107. $(".hfAutoCompleteId_billfromaddressid").val(data.BillFromAddressId);
  1108. $(".txtAutoComplete_billfromaddressid").append(new Option(data.BillFromAddressName, data.BillFromAddressId, true));
  1109. $(".hfAutoCompleteId_billtoaddressid").val(data.BillToAddressId);
  1110. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillToAddressName, data.BillToAddressId, true));
  1111. $(".hfAutoCompleteId_shiptoaddressid").val(data.ShipToAddressId);
  1112. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShipToAddressName, data.ShipToAddressId, true));
  1113. $(".hfAutoCompleteId_shipfromaddressid").val(data.ShipFromAddressId);
  1114. $(".txtAutoComplete_shipfromaddressid").append(new Option(data.ShipFromAddressName, data.ShipFromAddressId, true));
  1115. }
  1116. else {
  1117. $(".hfAutoCompleteId_billfromaddressid").val(data.BillToAddressId);
  1118. $(".txtAutoComplete_billfromaddressid").append(new Option(data.BillToAddressName, data.BillToAddressId, true));
  1119. $(".hfAutoCompleteId_billtoaddressid").val(data.BillFromAddressId);
  1120. $(".txtAutoComplete_billtoaddressid").append(new Option(data.BillFromAddressName, data.BillFromAddressId, true));
  1121. $(".hfAutoCompleteId_shiptoaddressid").val(data.ShipFromAddressId);
  1122. $(".txtAutoComplete_shiptoaddressid").append(new Option(data.ShipFromAddressName, data.ShipFromAddressId, true));
  1123. $(".hfAutoCompleteId_shipfromaddressid").val(data.ShipToAddressId);
  1124. $(".txtAutoComplete_shipfromaddressid").append(new Option(data.ShipToAddressName, data.ShipToAddressId, true));
  1125. }
  1126. InvoiceItem.Instance().loadLobAndSp();
  1127. InvoiceItem.Instance().getGSTNo();
  1128. $('.txtAutoComplete_lobid').empty();
  1129. $(".txtAutoComplete_lobid").append(new Option(data.LobName, data.LobId, true));
  1130. $(".hfAutoCompleteId_lobid").val(data.LobId);
  1131. $('.txtAutoComplete_salespersonid').empty();
  1132. $('.txtAutoComplete_salespersonid').append(new Option(data.SalesPersonName, data.SalesPersonId, true));
  1133. $('.hfAutoCompleteId_salespersonid').val(data.SalesPersonId);
  1134. $('hdn_OrganizationId').val(data.OrganizationId);
  1135. $("#hfInv_OrganizationName").val(data.OrganizationName);
  1136. $('.txtAutoComplete_paymenttermid').empty();
  1137. $('.hfAutoCompleteId_paymenttermid').val(data.PaymentTermId);
  1138. $('.txtAutoComplete_paymenttermid').append(new Option(data.PaymentTermName, data.PaymentTermId, true));
  1139. if (data.SeriesId != 0 && $('#hfInv_IsRetun').val() != "1") {
  1140. $(".txtSeriesAutoComplete_seriesid").empty();
  1141. $(".hfSeriesAutoCompleteId_seriesid").val(0);
  1142. $(".txtSeriesAutoComplete_seriesid").append(new Option(data.SeriesName, data.SeriesId, true));
  1143. $(".hfSeriesAutoCompleteId_seriesid").val(data.SeriesId);
  1144. }
  1145. else {
  1146. $(".txtSeriesAutoComplete_seriesid").prop("disabled", false);
  1147. if (data.SeriesId == 0 && data.InvoiceNo != null && data.InvoiceNo != "") {
  1148. $(".isManualSeries_seriesid").prop("checked", true);
  1149. $(".TextManualSeries").val(data.InvoiceNo);
  1150. }
  1151. else {
  1152. var Addr = $(".txtAutoComplete_billtoaddressid option:selected").val();
  1153. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6")
  1154. Addr = $(".txtAutoComplete_billfromaddressid option:selected").val();
  1155. InvoiceItem.Instance().bindSeries($(".txtAutoComplete_lobid option:selected").val(), Addr);
  1156. }
  1157. }
  1158. if (($('#hfInv_IsRetun').val() != "1") && ($('.hdn_invoicetypeid').val() == "4" || $('.hdn_invoicetypeid').val() == "7" || $('.hdn_invoicetypeid').val() == "6" || $('.hdn_invoicetypeid').val() == "3")) {
  1159. $(".txtSeriesAutoComplete_seriesid").prop("disabled", true);
  1160. }
  1161. if (data.RefNo != "" && data.RefNo != null)
  1162. $(".txt_refno").val(data.RefNo);
  1163. $(".hdn_refinvoiceid").val(data.RefInvoiceId);
  1164. if ($('#hfInv_IsRetun').val() == "1" && ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4"))
  1165. $(".txt_refno").val(data.InvoiceNo);
  1166. if (data.AdjustmentAccountId != 0) {
  1167. $("#txt_AdjustmentAccountName").append(new Option(data.AdjustmentAccountName, data.AdjustmentAccountId, true));
  1168. $("#txt_AdjustmentAccountName").val(data.AdjustmentAccountId);
  1169. $("#hf_AdjustmentAccountId").val(data.AdjustmentAccountId);
  1170. }
  1171. if (data.AdjustmentAccountId == 0)
  1172. $('#txt_AdjustmentAccountName').empty();
  1173. if (data.AutoAdjustment == true) {
  1174. $('#chk_AutoAdjustment').prop('checked', true);
  1175. $('#txt_Adjustment').prop("disabled", true);
  1176. $(".span_AdjustmentAccountName").removeClass('hidden');
  1177. $("#txt_AdjustmentAccountName").addClass('required');
  1178. }
  1179. else {
  1180. $('#chk_AutoAdjustment').prop('checked', false);
  1181. $('#txt_Adjustment').prop("disabled", false);
  1182. $("#txt_AdjustmentAccountName").removeClass('required');
  1183. $(".span_AdjustmentAccountName").addClass('hidden');
  1184. }
  1185. $('#txt_Adjustment').val(data.Adjustment);
  1186. if (data.Adjustment != 0) {
  1187. $('.span_AdjustmentAccountName').removeClass('hidden');
  1188. $("#txt_AdjustmentAccountName").addClass('required');
  1189. }
  1190. else {
  1191. $('.span_AdjustmentAccountName').addClass('hidden');
  1192. $("#txt_AdjustmentAccountName").removeClass('required');
  1193. }
  1194. if (data.InvoiceStatusId == 6) {
  1195. $('#btnInvoiceItem').hide();
  1196. }
  1197. var Iswalkincustomer = false;
  1198. var contactid = data.OrgContactId;
  1199. if (data.OrgContactId == 0) {
  1200. Iswalkincustomer = true;
  1201. contactid = data.OrganizationId;
  1202. }
  1203. InvoiceItem.Instance().IsCustomerIndustrial(data.LobId, data.OrganizationId);
  1204. $(".chk_excludefromcampaign").prop("checked", data.ExcludeFromCampaign);
  1205. $("#hfId_istaxinclusive").val(data.IsTaxInclusive);
  1206. InvoiceItem.Instance().isOfferChargeApplied = data.IsOfferChargeApplied;
  1207. $(".dropdown_istaxinclusive").val(data.IsTaxInclusive.toString());
  1208. $(".dropdown_paymentmethodid").val(data.PaymentMethodId);
  1209. InvoiceItem.Instance().GetAvailableWallets(data.InvoiceId);
  1210. InvoiceItem.Instance().loadOrderPendingItems();
  1211. });
  1212. $(".txtAutoComplete_orgcontactid").change(function () {
  1213. InvoiceItem.Instance().LoadContactDetails();
  1214. });
  1215. if (data.GSTNO != "" && data.GSTNO != null)
  1216. $(".txt_gstno").val(data.GSTNO);
  1217. 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) {
  1218. if (res.result != null) {
  1219. InvoiceItem.Instance().TurnOver = res.result.TurnOver;
  1220. InvoiceItem.Instance().ContactTcsEnable = res.result.Enable;
  1221. InvoiceItem.Instance().EnableTenantTcs = res.result.EnableTenantTcs;
  1222. InvoiceItem.Instance().PanAvailable = res.result.PanAvailable;
  1223. InvoiceItem.Instance().TaxRate = res.result.TaxRate;
  1224. $(".hdn_tcstaxcodeaccountid").val(res.result.TCSTaxCodeAccountId);
  1225. $(".hdn_tcstaxcodeid").val(res.result.TCSTaxCodeId);
  1226. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
  1227. if (InvoiceItem.Instance().ContactTcsEnable == true && InvoiceItem.Instance().EnableTenantTcs == true && data.TcsApplied == true) {
  1228. $("#chk_tcsapplied").prop("checked", true);
  1229. $("#hdnchk_tcsapplied").val("true");
  1230. $("#div_tcstaxrate").removeClass("hidden");
  1231. $(".div_tcsadjustment").removeClass("hidden");
  1232. $("#div_tcsamount").removeClass("hidden");
  1233. $(".number_tcsamount").prop("disabled", true);
  1234. }
  1235. }
  1236. }
  1237. });
  1238. $("chk_tcsapplies").prop("checked", data.TcsApplied);
  1239. $(".hdn_tcstaxcodeid").val(data.TcsTaxCodeId);
  1240. $(".hdn_tcstaxcodeaccountid").val(data.TcsTaxCodeAccountId);
  1241. $(".number_tcstaxrate").val(data.TcsTaxRate);
  1242. $(".number_tcstaxrate").prop("disabled", true);
  1243. $(".txt_tcsadjustment").val(data.TcsAdjustment);
  1244. $(".number_tcsamount").val(data.TcsAmount);
  1245. $(".number_tcsamount").prop("disabled", true);
  1246. $(".number_tdsamount").prop("disabled", true);
  1247. $(".number_tdstaxrate").prop("disabled", true);
  1248. InvoiceItem.Instance().ContactTcsEnable = data.TcsApplied;
  1249. InvoiceItem.Instance().TaxRate = data.TcsTaxRate;
  1250. if (data.TcsApplied == true) {
  1251. $("#div_tcstaxrate").removeClass("hidden");
  1252. $(".div_tcsadjustment").removeClass("hidden");
  1253. $("#div_tcsamount").removeClass("hidden");
  1254. }
  1255. else {
  1256. $("#div_tcstaxrate").addClass("hidden");
  1257. $(".div_tcsadjustment").addClass("hidden");
  1258. $("#div_tcsamount").addClass("hidden");
  1259. }
  1260. $("#chk_tcsapplied").unbind();
  1261. $("#chk_tcsapplied").change(function () {
  1262. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  1263. $("#txt_Adjustment").val(0);
  1264. $(".hdn_adjustment").val(0);
  1265. }
  1266. if ($(this).prop('checked') == true) {
  1267. $(".divCustomProperties_tdstaxrate").addClass("hidden");
  1268. $(".divCustomProperties_tdsamount").addClass("hidden");
  1269. $(".divCustomProperties_tdstaxcodeid").addClass("hidden");
  1270. $(".chk_tdsapplied").attr("disabled");
  1271. $('#chk_tdsapplied').prop('checked', false);
  1272. }
  1273. else {
  1274. $(".chk_tdsapplied").removeAttr("disabled");
  1275. }
  1276. $(".div_tcsadjustment").addClass("floating-label-form-group-with-value");
  1277. if ($(this).prop('checked') == true && InvoiceItem.Instance().EnableTenantTcs == false && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  1278. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  1279. $("#hdnchk_tcsapplied").val("false");
  1280. $('#chk_tcsapplied').prop('checked', false);
  1281. }
  1282. else {
  1283. if ($(this).prop('checked') == true && $(".hdn_invoicetypeid").val() == "1") {
  1284. bootbox.confirm("Confirm if sale value is > 50,00,000 for this customer.In this current Financial Year.", function (result) {
  1285. if (result) {
  1286. $("#div_tcstaxrate").removeClass("hidden");
  1287. $(".div_tcsadjustment").removeClass("hidden");
  1288. $("#div_tcsamount").removeClass("hidden");
  1289. InvoiceItem.Instance().update_total();
  1290. InvoiceItem.Instance().TotalAdjustment();
  1291. }
  1292. else {
  1293. $("#div_tcstaxrate").addClass("hidden");
  1294. $(".div_tcsadjustment").addClass("hidden");
  1295. $("#div_tcsamount").addClass("hidden");
  1296. $('#chk_tcsapplied').prop('checked', false);
  1297. InvoiceItem.Instance().update_total();
  1298. InvoiceItem.Instance().TotalAdjustment();
  1299. }
  1300. });
  1301. }
  1302. else if ($(this).prop('checked') == true) {
  1303. $("#div_tcstaxrate").removeClass("hidden");
  1304. $(".div_tcsadjustment").removeClass("hidden");
  1305. $("#div_tcsamount").removeClass("hidden");
  1306. $("#chk_tdsapplied").removeAttr("disabled");
  1307. InvoiceItem.Instance().update_total();
  1308. InvoiceItem.Instance().TotalAdjustment();
  1309. }
  1310. else if ($(this).prop('checked') == false) {
  1311. $("#div_tcstaxrate").addClass("hidden");
  1312. $(".div_tcsadjustment").addClass("hidden");
  1313. $("#div_tcsamount").addClass("hidden");
  1314. $(".number_tcstaxrate").val(data.TcsTaxRate);
  1315. $(".number_tcstaxrate").prop("disabled", true);
  1316. $(".txt_tcsadjustment").val(data.TcsAdjustment);
  1317. $(".number_tcsamount").val(data.TcsAmount);
  1318. $(".number_tcsamount").prop("disabled", true);
  1319. InvoiceItem.Instance().update_total();
  1320. InvoiceItem.Instance().TotalAdjustment();
  1321. }
  1322. }
  1323. });
  1324. if ($("#chk_tdsapplied").prop('checked') == false) {
  1325. $(".divCustomProperties_tdstaxrate").addClass("hidden");
  1326. $(".divCustomProperties_tdsamount").addClass("hidden");
  1327. $(".divCustomProperties_tdstaxcodeid").addClass("hidden");
  1328. }
  1329. else
  1330. $("#chk_tcsapplied").attr("disabled");
  1331. $(".txt_tcsadjustment").unbind();
  1332. $(".txt_tcsadjustment").blur(function () {
  1333. InvoiceItem.Instance().update_total();
  1334. InvoiceItem.Instance().TotalAdjustment();
  1335. });
  1336. });
  1337. });
  1338. }
  1339. loadOrderPendingItems() {
  1340. var InstalledAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  1341. let instance = this;
  1342. let invoiceid = $(".hdn_invoiceid").val();
  1343. var orderid = $(".hdn_orderid").val();
  1344. var Dcid = $(".hdn_dcid").val();
  1345. var fromOrder = false;
  1346. var items = [];
  1347. var Invoiceitem = [];
  1348. $(".item-addedrow").remove();
  1349. var url = "";
  1350. if (Dcid != 0 && Dcid != undefined && orderid == 0) {
  1351. fromOrder = false;
  1352. url = "apis/v4/bizgaze/transact/Dc/getpendingdcitemsforinvoice/dcid/" + Dcid;
  1353. }
  1354. if (Dcid == 0 || Dcid == undefined || InvoiceItem.Instance().OrderSettingId == 2) {
  1355. if (orderid != "0" && orderid != undefined) {
  1356. fromOrder = true;
  1357. url = "apis/v4/bizgaze/transact/Orders/getpendingitemsforinvoice/orderid/" + orderid + "/ismergeorder/false";
  1358. }
  1359. }
  1360. else if (Dcid != 0 && Dcid != undefined) {
  1361. fromOrder = false;
  1362. url = "apis/v4/bizgaze/transact/Dc/getpendingdcitemsforinvoice/dcid/" + Dcid;
  1363. }
  1364. if (invoiceid != 0 && invoiceid != undefined && invoiceid != "null") {
  1365. fromOrder = false;
  1366. if ($('#hfInv_IsRetun').val() == "1") {
  1367. if ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")
  1368. url = "apis/v4/bizgaze/transact/invoices/getinvoiceitemsbyinvoiceid/invoiceid/" + invoiceid + "/isreturn/true/itemid/0";
  1369. }
  1370. else
  1371. url = "apis/v4/bizgaze/transact/invoices/getinvoiceitemsbyinvoiceid/invoiceid/" + invoiceid + "/isreturn/false/itemid/0";
  1372. }
  1373. if (url != "") {
  1374. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceItems(url).then(function (response) {
  1375. var oldTaxId = 0;
  1376. var totalQty = 0;
  1377. if (response.result != null && response.result.length > 0)
  1378. instance.ShowOrHideSaveBtn(false);
  1379. for (var i = 0; i < response.result.length; i++) {
  1380. var item = response.result[i];
  1381. var invoiceItemId = 0;
  1382. totalQty += item.Quantity;
  1383. if (invoiceid != "0" && invoiceid != undefined && invoiceid != "null") {
  1384. invoiceItemId = item.InvoiceItemId;
  1385. item.IsOfferChargeApplied = InvoiceItem.Instance().isOfferChargeApplied;
  1386. }
  1387. InvoiceItem.Instance().isOfferChargeApplied = true;
  1388. $(".hdn_isofferchargeapplied").val('true');
  1389. var refInvoiceItemId = 0;
  1390. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $("#hf_AppSettingName").val() == "Create Return")
  1391. refInvoiceItemId = item.InvoiceItemId;
  1392. if (i == 0)
  1393. oldTaxId = item.TaxGroupId;
  1394. if (oldTaxId != item.TaxGroupId && i != 0)
  1395. $('#addDiscount').addClass('hidden');
  1396. var maxQty = 0;
  1397. if (item.OrderItemPendingQty > 0)
  1398. maxQty = item.OrderItemPendingQty;
  1399. var pendingQuantity = item.OrderItemPendingQty > 0 ? item.OrderItemPendingQty : 0;
  1400. if (invoiceItemId != 0) {
  1401. maxQty = item.Quantity + pendingQuantity;
  1402. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4"))
  1403. maxQty = item.Quantity;
  1404. }
  1405. if (item.DcItemId == undefined)
  1406. item.DcItemId = 0;
  1407. if (item.TaxAdjustment == undefined)
  1408. item.TaxAdjustment = 0;
  1409. if (item.AssesableAdjustment == undefined)
  1410. item.AssesableAdjustment = 0;
  1411. if (item.IsFoc == undefined)
  1412. item.IsFoc = false;
  1413. if (item.OfferItemId == undefined)
  1414. item.OfferItemId = 0;
  1415. if (item.DiscountPercent == undefined)
  1416. item.DiscountPercent = 0;
  1417. if (item.DiscountValue == undefined)
  1418. item.DiscountValue = 0;
  1419. if (item.IsSpecialPrice == undefined)
  1420. item.IsSpecialPrice = false;
  1421. if (item.MrpId == 0)
  1422. item.EnableMRP = false;
  1423. var itemRow = {
  1424. orderItemId: item.OrderItemId,
  1425. invoiceItemId: invoiceItemId,
  1426. itemName: item.ItemName,
  1427. itemId: item.ItemId,
  1428. itemSKU: item.ItemSKU,
  1429. unitName: item.UnitName,
  1430. packSize: item.PackSize,
  1431. packCount: item.PackCount,
  1432. packs: item.Packs,
  1433. quantity: item.Quantity,
  1434. availPacks: item.AvailablePacks,
  1435. availQty: item.AvailableQty,
  1436. listPrice: 0,
  1437. description: item.Description,
  1438. taxGroupName: item.TaxGroupName,
  1439. taxGroupId: item.TaxGroupId,
  1440. isTaxInclusive: $("#hfId_istaxinclusive").val(),
  1441. addlDiscountPercent: item.DiscountPercent,
  1442. addlDiscountValue: item.DiscountAmount,
  1443. creditNote: 0,
  1444. priceListId: 0,
  1445. batchId: 0,
  1446. unitPrice: item.UnitPrice,
  1447. invoiceallocations: null,
  1448. exciseInvoiceItem: null,
  1449. accountId: item.LedgerId,
  1450. accountName: item.LedgerName,
  1451. walletId: 0,
  1452. Adjustment: 0,
  1453. IsFoc: item.IsFoc,
  1454. TariffNo: "",
  1455. exciseAmount: item.ExciseAmount,
  1456. discountName: "",
  1457. discountId: 0,
  1458. refNo: item.RefNo,
  1459. DiscountGroupId: item.DiscountGroupId,
  1460. DiscountGroupName: item.DiscountGroupName,
  1461. ExchangeItem: item.ExchangeDC,
  1462. maxQty: maxQty,
  1463. RefInvoiceItemId: refInvoiceItemId,
  1464. MrpId: item.MrpId,
  1465. taxAdjustment: item.TaxAdjustment,
  1466. assesableAdjustment: item.AssesableAdjustment,
  1467. inventoryTypeId: item.InventoryTypeId,
  1468. IsBoMItem: item.IsBoMItem,
  1469. dcItemId: item.DcItemId,
  1470. TotalRowAmount: 0,
  1471. TotalDiscount: 0,
  1472. BatchId: item.BatchId,
  1473. OfferItemId: item.OfferItemId,
  1474. AlternateUnitId: item.AlternateUnitId,
  1475. DefaultSize: item.DefaultSize,
  1476. ParentBOMItemId: item.ParentBOMItemId,
  1477. IsSpecialPrice: item.IsSpecialPrice,
  1478. IsMultipleUOMs: item.IsMultipleUOMs,
  1479. MultipleUoms: item.MultipleUOMs,
  1480. IsManualUOM: item.IsManualUOM,
  1481. ConversionQuantity: item.ConversionQuantity,
  1482. AlternateUnitName: item.AlternateUnitName,
  1483. };
  1484. var EnableMrp = item.EnableMRP;
  1485. var EnableBatch = item.EnableBatch;
  1486. if (item.IsFoc == true)
  1487. Invoiceitem.push(itemRow);
  1488. else if (item.DcItemId != 0 && EnableMrp != true && EnableBatch != true)
  1489. Invoiceitem.push(itemRow);
  1490. else if (item.InvoiceItemId == 0) {
  1491. 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)
  1492. Invoiceitem.push(itemRow);
  1493. }
  1494. else if (item.InvoiceItemId == 0) {
  1495. 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))
  1496. Invoiceitem.push(itemRow);
  1497. }
  1498. else if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && ((EnableMrp != true && EnableBatch != true)))
  1499. Invoiceitem.push(itemRow);
  1500. else if (($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3") && EnableMrp != true && EnableBatch != true)
  1501. Invoiceitem.push(itemRow);
  1502. else if ($(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7")
  1503. Invoiceitem.push(itemRow);
  1504. else {
  1505. if (item.InventoryTypeId != 5 && item.InventoryTypeId != 6 && item.InventoryTypeId != 7) {
  1506. var total = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  1507. var nonexcise = total - itemRow.exciseAmount;
  1508. var disc = ((nonexcise * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  1509. var Rowtotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(total - disc, 3);
  1510. InvoiceItem.Instance().SplitedInvoiceItemList.push({
  1511. orderItemId: item.OrderItemId,
  1512. invoiceItemId: invoiceItemId,
  1513. itemName: item.ItemName,
  1514. itemId: item.ItemId,
  1515. itemSKU: item.ItemSKU,
  1516. unitName: item.UnitName,
  1517. packSize: item.PackSize,
  1518. packCount: item.PackCount,
  1519. packs: item.Packs,
  1520. quantity: item.Quantity,
  1521. availPacks: item.AvailablePacks,
  1522. availQty: item.AvailableQty,
  1523. listPrice: 0,
  1524. description: item.Description,
  1525. taxGroupName: item.TaxGroupName,
  1526. taxGroupId: item.TaxGroupId,
  1527. isTaxInclusive: $("#hfId_istaxinclusive").val(),
  1528. addlDiscountPercent: item.DiscountPercent,
  1529. addlDiscountValue: item.DiscountAmount,
  1530. creditNote: 0,
  1531. priceListId: 0,
  1532. batchId: 0,
  1533. unitPrice: item.UnitPrice,
  1534. invoiceallocations: null,
  1535. exciseInvoiceItem: null,
  1536. accountId: item.LedgerId,
  1537. accountName: item.LedgerName,
  1538. walletId: 0,
  1539. Adjustment: 0,
  1540. IsFoc: 0,
  1541. TariffNo: "",
  1542. exciseAmount: item.ExciseAmount,
  1543. discountName: "",
  1544. discountId: 0,
  1545. refNo: item.RefNo,
  1546. DiscountGroupId: item.DiscountGroupId,
  1547. DiscountGroupName: item.DiscountGroupName,
  1548. ExchangeItem: item.ExchangeDC,
  1549. maxQty: maxQty,
  1550. RefInvoiceItemId: refInvoiceItemId,
  1551. MrpId: item.MrpId,
  1552. taxAdjustment: item.TaxAdjustment,
  1553. assesableAdjustment: item.AssesableAdjustment,
  1554. inventoryTypeId: item.InventoryTypeId,
  1555. IsBoMItem: item.IsBoMItem,
  1556. dcItemId: item.DcItemId,
  1557. TotalRowAmount: Rowtotal,
  1558. TotalDiscount: disc,
  1559. BatchId: item.BatchId,
  1560. TotalAmount: Rowtotal,
  1561. ParentBOMItemId: item.ParentBOMItemId
  1562. });
  1563. if (items.length != 0 && items.find(x => x.itemId == item.ItemId) != undefined) {
  1564. var multipleExist = items.find(x => x.itemId == item.ItemId);
  1565. multipleExist.quantity += itemRow.quantity;
  1566. var RowTotal = 0;
  1567. var rowtotal = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  1568. var nonexiceamount = rowtotal - itemRow.exciseAmount;
  1569. var discount = ((nonexiceamount * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  1570. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  1571. RowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowtotal - discount, 3);
  1572. multipleExist.TotalRowAmount = Number(multipleExist.TotalRowAmount) + Number(RowTotal);
  1573. multipleExist.TotalDiscount = Number(multipleExist.TotalDiscount) + Number(discount);
  1574. if (InvoiceItem.Instance().OrderSettingId == 1) {
  1575. var Qty = Number(maxQty);
  1576. multipleExist.maxQty = Qty + Number(multipleExist.maxQty);
  1577. }
  1578. else {
  1579. var Qty = Number(item.Quantity);
  1580. multipleExist.maxQty = Qty + Number(multipleExist.maxQty);
  1581. }
  1582. }
  1583. else {
  1584. var RowTotal = 0;
  1585. var rowtotal = Number((itemRow.quantity * itemRow.unitPrice) + itemRow.exciseAmount + itemRow.Adjustment + itemRow.assesableAdjustment);
  1586. var nonexiceamount = rowtotal - itemRow.exciseAmount;
  1587. var discount = ((nonexiceamount * itemRow.addlDiscountPercent) / 100) + (itemRow.quantity * itemRow.addlDiscountValue);
  1588. discount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discount, 3));
  1589. RowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowtotal - discount, 3);
  1590. itemRow.TotalRowAmount = Number(itemRow.TotalRowAmount) + Number(RowTotal);
  1591. itemRow.TotalDiscount = Number(discount);
  1592. items.push(itemRow);
  1593. }
  1594. }
  1595. else {
  1596. Invoiceitem.push(itemRow);
  1597. }
  1598. }
  1599. $.each(item.InvItemTaxAdjustments, function (e) {
  1600. var data = $(this);
  1601. var rowData = data[0];
  1602. InvoiceItem.Instance().invItemTaxAdjustmentList.push(rowData);
  1603. });
  1604. }
  1605. for (let j1 = 0; j1 < items.length; j1++) {
  1606. let j = items[j1];
  1607. var emptyRow = {
  1608. orderItemId: j.orderItemId,
  1609. invoiceItemId: 0,
  1610. itemName: j.itemName,
  1611. itemId: j.itemId,
  1612. itemSKU: j.itemSKU,
  1613. unitName: "",
  1614. packSize: 0,
  1615. packCount: 0,
  1616. packs: 0,
  1617. quantity: j.quantity,
  1618. availPacks: 0,
  1619. availQty: j.availQty,
  1620. listPrice: 0,
  1621. description: "",
  1622. taxGroupName: j.taxGroupName,
  1623. taxGroupId: j.taxGroupId,
  1624. isTaxInclusive: $("#hf_istaxinclusive").val(),
  1625. addlDiscountPercent: 0,
  1626. addlDiscountValue: j.addlDiscountValue,
  1627. creditNote: 0,
  1628. priceListId: 0,
  1629. batchId: 0,
  1630. unitPrice: j.unitPrice,
  1631. invoiceallocations: null,
  1632. exciseInvoiceItem: null,
  1633. accountId: j.accountId,
  1634. accountName: j.accountName,
  1635. walletId: 0,
  1636. Adjustment: 0,
  1637. IsFoc: j.IsFoc,
  1638. TariffNo: "",
  1639. exciseAmount: 0,
  1640. discountName: "",
  1641. discountId: 0,
  1642. refNo: "",
  1643. DiscountGroupId: 0,
  1644. DiscountGroupName: '',
  1645. RefInvoiceItemId: 0,
  1646. MrpId: j.MrpId,
  1647. taxAdjustment: 0,
  1648. assesableAdjustment: 0,
  1649. inventoryTypeId: 0,
  1650. dcItemId: 0,
  1651. TotalRowAmount: j.TotalRowAmount,
  1652. BatchId: j.BatchId,
  1653. maxQty: j.maxQty,
  1654. TotalDiscount: j.TotalDiscount,
  1655. ParentBOMItemId: j.ParentBOMItemId,
  1656. IsSpecialPrice: j.IsSpecialPrice
  1657. };
  1658. if (j.dcItemId != 0)
  1659. InvoiceItem.Instance().dcItemIds.push(j.dcItemId);
  1660. InvoiceItem.Instance().addDataRow(emptyRow, true);
  1661. if (items.length - 1 == j1) {
  1662. if (invoiceid != 0)
  1663. instance.GetDiscounts();
  1664. instance.ShowOrHideSaveBtn(true);
  1665. }
  1666. }
  1667. for (let k1 = 0; k1 < Invoiceitem.length; k1++) {
  1668. let k = Invoiceitem[k1];
  1669. if (k.dcItemId != 0)
  1670. InvoiceItem.Instance().dcItemIds.push(k.dcItemId);
  1671. InvoiceItem.Instance().addDataRow(k, false);
  1672. if (Invoiceitem.length - 1 == k1) {
  1673. if (invoiceid != 0)
  1674. instance.GetDiscounts();
  1675. instance.ShowOrHideSaveBtn(true);
  1676. }
  1677. }
  1678. $("#totalinvoiceqty").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalQty, 2));
  1679. });
  1680. }
  1681. }
  1682. getwalletinvoiceditems() {
  1683. var JournalAlloc = new Array();
  1684. $("#tbl_WalletItems").find(".walletitem-addedrow").each(function () {
  1685. JournalAlloc.push({
  1686. journalAllocId: $(this).find(".journalAllocId").val(),
  1687. RefAllocId: $(this).find(".refAllocId").val(),
  1688. JournalId: $("#hf_" + $("#hfLayout_InstalledPageId").val() + "_Invoiceid").val(),
  1689. AdjustedAmount: Number($(this).find(".hfAdjustedAmount").val()),
  1690. TotalAmount: Number($(this).find(".totalAmount").text()),
  1691. IsWallet: true,
  1692. CurrentAmount: Number($(this).find(".currentAmount").val()),
  1693. });
  1694. });
  1695. return JournalAlloc;
  1696. }
  1697. ShowOrHideSaveBtn(IsShow) {
  1698. let instance = this;
  1699. if (!IsShow) {
  1700. instance.navigationHelper.showLoading();
  1701. $("#btnDynamicSave").prop("disabled", true);
  1702. }
  1703. else {
  1704. instance.navigationHelper.hideLoading();
  1705. $("#btnDynamicSave").prop("disabled", false);
  1706. }
  1707. }
  1708. getInvoiceItems() {
  1709. var invItemList = new Array();
  1710. $(".InvoiceItems").find(".item-row").each(function () {
  1711. if (!$(this).hasClass('SplitItem')) {
  1712. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  1713. let ParentBOMItemId = $(this).find(".hf_ParentBOMItemId").val();
  1714. if (ParentBOMItemId == null)
  1715. ParentBOMItemId = 0;
  1716. var invoicetermid = $(this).find(".invoiceTermId").val();
  1717. var invoiceitemid = Number($(this).find(".selectedInvoiceItemId").val());
  1718. var refInvoiceitemid = Number($(this).find(".refInvoiceItemId").val());
  1719. var orderItemId = Number($(this).find(".orderItemId").val());
  1720. var ItemId = Number($(this).find(".selectedItemId").val());
  1721. var packs = 0;
  1722. var prodprice = Number($(this).find(".prodPrice").val());
  1723. var quantity = Number($(this).find(".prodQuantity").val());
  1724. var prodpricelist = 0;
  1725. var description = $(this).find(".prodDesc").val();
  1726. var MrpId = Number($(this).find(".hfMrpId").val());
  1727. var discountAmount = 0;
  1728. var discountPercent = 0;
  1729. var rowTotal = Number($(this).find(".prodTotalPrice").text());
  1730. if (($(".hdn_invoicetypeid").val() == "2") && invoiceitemid != 0) {
  1731. rowTotal = Number($(this).find(".hfRowTotalwithAdjustment").val());
  1732. }
  1733. var Quantity = Number($(this).find(".prodQuantity").val());
  1734. var ConversionQuantity = Quantity;
  1735. let SelectedUnitId = 0;
  1736. let DefaultSize = 0;
  1737. let AlternateSize = 0;
  1738. if ($(this).find(".hf_IsMultipleUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
  1739. let ItemId = Number($(this).find(".selectedItemId").val());
  1740. SelectedUnitId = Number($(this).find(".ddl_MultipleUOMs").val());
  1741. if (SelectedUnitId != 0 && SelectedUnitId != 1) {
  1742. var Uom = InvoiceItem.Instance().UOMs.find(x => x.ItemId == ItemId);
  1743. var SelectedUOM = Uom.MultipleUOMs.find(x => x.SchemaDetailId == SelectedUnitId);
  1744. DefaultSize = SelectedUOM.DefaultSize;
  1745. AlternateSize = SelectedUOM.AlternateSize;
  1746. ConversionQuantity = Number(Quantity) * (AlternateSize / DefaultSize);
  1747. }
  1748. }
  1749. else if ($(this).find(".hf_IsManualUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
  1750. SelectedUnitId = Number($(this).find(".hf_AlternateUnitId").val());
  1751. ConversionQuantity = Number($(this).find(".hf_ConversionQuantity").val());
  1752. }
  1753. 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) {
  1754. discountAmount = Number($(this).find('.inv_txtaddldiscount').val());
  1755. }
  1756. else if ($(this).find(".btnInvoice_DiscType option:selected").text().trim() == '%' && $(this).find('.inv_txtaddldiscount').val() != '' && $(this).find('.inv_txtaddldiscount').val() != undefined) {
  1757. discountPercent = Number($(this).find('.inv_txtaddldiscount').val());
  1758. }
  1759. var TaxGroupId = Number($(this).find(".hfProdTax").val());
  1760. let accountid = Number($(this).find(".txt_Account").val());
  1761. let foc = ($(this).find(".hf_IsFoc").val() == 'true');
  1762. invItemList.push({
  1763. InvoiceItemId: invoiceitemid,
  1764. OrderItemId: orderItemId,
  1765. ItemId: ItemId,
  1766. Packs: packs,
  1767. TaxGroupId: TaxGroupId,
  1768. Description: description,
  1769. PriceListId: prodpricelist,
  1770. UnitPrice: prodprice,
  1771. DiscountAmount: discountAmount,
  1772. DiscountPercent: discountPercent,
  1773. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  1774. AccountId: accountid,
  1775. Adjustment: Number($(this).find(".hfRowTotalAdjustment").val()),
  1776. TotalAmount: Number(rowTotal),
  1777. Quantity: Number(Quantity),
  1778. ExciseAmount: 0,
  1779. RefNo: $(this).find(".refNo").val(),
  1780. DiscountGroupId: Number($(this).find("#hfProdDiscountGroupId").val()),
  1781. RefInvoiceItemId: Number(refInvoiceitemid),
  1782. MrpId: Number(MrpId),
  1783. DcItemId: Number($(this).find(".dcItemId").val()),
  1784. BatchId: 0,
  1785. IsFoc: foc,
  1786. OfferItemId: ($(this).find(".hfOfferedItemId").val() == null || $(this).find(".hfOfferedItemId").val() == undefined) ? 0 : Number($(this).find(".hfOfferedItemId").val()),
  1787. AlternateUnitId: SelectedUnitId,
  1788. DefaultSize: DefaultSize,
  1789. ParentBOMItemId: Number(ParentBOMItemId),
  1790. ConversionQuantity: Number(ConversionQuantity)
  1791. });
  1792. }
  1793. }
  1794. });
  1795. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  1796. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_IsRetun').val() == "1") {
  1797. InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId = 0;
  1798. }
  1799. invItemList.push({
  1800. InvoiceItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId),
  1801. OrderItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].orderItemId),
  1802. ItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId),
  1803. TaxGroupId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].taxGroupId),
  1804. Description: InvoiceItem.Instance().SplitedInvoiceItemList[i].description,
  1805. PriceListId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].priceListId),
  1806. UnitPrice: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice),
  1807. DiscountAmount: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountValue),
  1808. DiscountPercent: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountPercent),
  1809. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  1810. AccountId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].accountId),
  1811. Adjustment: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].Adjustment),
  1812. TotalAmount: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].TotalAmount),
  1813. Quantity: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity),
  1814. ExciseAmount: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount),
  1815. RefNo: InvoiceItem.Instance().SplitedInvoiceItemList[i].refNo,
  1816. DiscountGroupId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].DiscountGroupId),
  1817. RefInvoiceItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].RefInvoiceItemId),
  1818. MrpId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].MrpId) == -1 ? 0 : Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].MrpId),
  1819. DcItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId),
  1820. BatchId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].BatchId),
  1821. IsFoc: false,
  1822. OfferItemId: 0,
  1823. });
  1824. }
  1825. $(".InvoiceItems").find(".discount-row").each(function () {
  1826. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  1827. var rowname = "discount-row";
  1828. var appliedOnWhole = false;
  1829. var totalElement = $(this).find(".netdiscount-row-total");
  1830. if (totalElement.length != 0) {
  1831. appliedOnWhole = true;
  1832. rowname = "netdiscount-row";
  1833. }
  1834. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  1835. var ItemId = $(this).find(".hfSelectedChargeId").val();
  1836. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  1837. var ledgerId = $(this).find(".hdnChargeLedgerId").val();
  1838. var percent = $(this).find(".percentage").val();
  1839. var value = $(this).find(".fixedvalue").val();
  1840. var desc = $(this).find(".discountDesc").val();
  1841. var totalamount = $(this).find("." + rowname + "-total").html();
  1842. invItemList.push({
  1843. InvoiceItemId: $(this).find(".selectedInvoiceItemId").val() == undefined ? 0 : Number($(this).find(".selectedInvoiceItemId").val()),
  1844. OrderItemId: 0,
  1845. ItemId: Number(ItemId),
  1846. Packs: 0,
  1847. TaxGroupId: Number($(this).find(".hfProdTax").val()),
  1848. Description: $(this).find(".discountDesc").val(),
  1849. PriceListId: 0,
  1850. UnitPrice: 0,
  1851. DiscountAmount: Number($(this).find(".fixedvalue").val()),
  1852. DiscountPercent: Number($(this).find(".percentage").val()),
  1853. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  1854. AccountId: Number($(this).find(".hf_Account").val()),
  1855. RowDiscount: Number(totalamount),
  1856. SendToWallet: 0,
  1857. Adjustment: 0,
  1858. TotalAmount: 0,
  1859. Quantity: 1,
  1860. ExciseAmount: 0,
  1861. RefNo: "",
  1862. DiscountGroupId: 0,
  1863. RefInvoiceItemId: 0,
  1864. MrpId: 0,
  1865. BatchId: 0,
  1866. DcItemId: Number($(this).find(".dcItemId").val()),
  1867. IsFoc: false,
  1868. OfferItemId: 0,
  1869. });
  1870. }
  1871. });
  1872. $(".netdiscount-row").each(function () {
  1873. var rowname = "";
  1874. var appliedOnWhole = false;
  1875. var totalElement = $(this).find(".netdiscount-row-total");
  1876. if (totalElement.length != 0) {
  1877. appliedOnWhole = true;
  1878. rowname = "netdiscount-row";
  1879. }
  1880. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  1881. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  1882. var ItemId = $(this).find(".hfSelectedChargeId").val();
  1883. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  1884. var ledgerId = $(this).find(".hdnChargeLedgerId").val();
  1885. var percent = $(this).find(".percentage").val();
  1886. var value = $(this).find(".fixedvalue").val();
  1887. var desc = $(this).find(".discountDesc").val();
  1888. var totalamount = $(this).find("." + rowname + "-total").html();
  1889. invItemList.push({
  1890. InvoiceItemId: $(this).find(".selectedInvoiceItemId").val() == undefined ? 0 : Number($(this).find(".selectedInvoiceItemId").val()),
  1891. OrderItemId: 0,
  1892. ItemId: Number(ItemId),
  1893. Packs: 0,
  1894. TaxGroupId: Number($(this).find(".hfProdTax").val()),
  1895. Description: $(this).find(".discountDesc").val(),
  1896. PriceListId: 0,
  1897. UnitPrice: 0,
  1898. DiscountAmount: Number($(this).find(".fixedvalue").val()),
  1899. DiscountPercent: Number($(this).find(".percentage").val()),
  1900. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  1901. AccountId: Number($(this).find(".hf_Account").val()),
  1902. RowDiscount: Number(totalamount),
  1903. SendToWallet: 0,
  1904. Adjustment: 0,
  1905. TotalAmount: 0,
  1906. Quantity: 1,
  1907. ExciseAmount: 0,
  1908. RefNo: "",
  1909. DiscountGroupId: 0,
  1910. RefInvoiceItemId: 0,
  1911. MrpId: 0,
  1912. BatchId: 0,
  1913. DcItemId: Number($(this).find(".dcItemId").val()),
  1914. IsFoc: false,
  1915. OfferItemId: 0,
  1916. });
  1917. }
  1918. });
  1919. $(".expense-row").each(function () {
  1920. var rowname = "";
  1921. var appliedOnWhole = false;
  1922. var totalElement = $(this).find(".expense-row-total");
  1923. if (totalElement.length != 0) {
  1924. appliedOnWhole = true;
  1925. rowname = "expense-row";
  1926. }
  1927. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  1928. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  1929. var ItemId = $(this).find(".hfSelectedChargeId").val();
  1930. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  1931. var ledgerId = $(this).find(".hdnChargeLedgerId").val();
  1932. var percent = $(this).find(".percentage").val();
  1933. var value = $(this).find(".fixedvalue").val();
  1934. var desc = $(this).find(".discountDesc").val();
  1935. var totalamount = $(this).find("." + rowname + "-total").html();
  1936. if (Number($(this).find(".expfixedvalue").val()) != 0 || Number($(this).find(".exppercentage").val()) != 0) {
  1937. invItemList.push({
  1938. InvoiceItemId: $(this).find(".selectedInvoiceItemId").val() == undefined ? 0 : Number($(this).find(".selectedInvoiceItemId").val()),
  1939. OrderItemId: 0,
  1940. ItemId: Number(ItemId),
  1941. Packs: 0,
  1942. TaxGroupId: Number($(this).find(".hfProdTax").val()),
  1943. Description: $(this).find(".expenseDesc").val(),
  1944. PriceListId: 0,
  1945. UnitPrice: 0,
  1946. DiscountAmount: -Number($(this).find(".expfixedvalue").val()),
  1947. DiscountPercent: -Number($(this).find(".exppercentage").val()),
  1948. IsTaxInclusive: Boolean($('.dropdown_istaxinclusive').val()),
  1949. AccountId: Number($(this).find(".hf_Account").val()),
  1950. RowDiscount: -Number(totalamount),
  1951. SendToWallet: 0,
  1952. Adjustment: 0,
  1953. TotalAmount: 0,
  1954. Quantity: 1,
  1955. ExciseAmount: 0,
  1956. RefNo: "",
  1957. DiscountGroupId: 0,
  1958. RefInvoiceItemId: 0,
  1959. MrpId: 0,
  1960. BatchId: 0,
  1961. DcItemId: Number($(this).find(".dcItemId").val()),
  1962. IsFoc: false,
  1963. OfferItemId: 0,
  1964. });
  1965. }
  1966. }
  1967. });
  1968. return invItemList;
  1969. }
  1970. getCharges() {
  1971. var ChargeList = new Array();
  1972. var chargeIndex = 0;
  1973. InvoiceItem.Instance().update_discount_total();
  1974. InvoiceItem.Instance().update_expense_total();
  1975. $(".discount-row,.netdiscount-row").each(function () {
  1976. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  1977. var rowname = "discount-row";
  1978. var appliedOnWhole = false;
  1979. var totalElement = $(this).find(".netdiscount-row-total");
  1980. if (totalElement.length != 0) {
  1981. appliedOnWhole = true;
  1982. rowname = "netdiscount-row";
  1983. }
  1984. if ($(this).find(".hfSelectedChargeId").val() != "" && $(this).find(".hfSelectedChargeId").val() != "0") {
  1985. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  1986. chargeIndex += 1;
  1987. var ChargeId = $(this).find(".hfSelectedChargeId").val();
  1988. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  1989. var ledgerId = $(this).find(".hf_Account").val();
  1990. var percent = $(this).find(".percentage").val();
  1991. var value = $(this).find(".fixedvalue").val();
  1992. var desc = $(this).find(".discountDesc").val();
  1993. var totalamount = $(this).find("." + rowname + "-total").html();
  1994. ChargeList.push({
  1995. InvoiceChargeId: Number(invoicechargeid),
  1996. ChargeId: Number(ChargeId),
  1997. ChargeTypeId: Number(chargeTypeId),
  1998. ChargeIndex: chargeIndex,
  1999. Percentage: Number(percent),
  2000. FixedAmount: Number(value),
  2001. ApplyWhole: appliedOnWhole,
  2002. Description: desc,
  2003. TotalAmount: Number(totalamount),
  2004. LedgerId: Number(ledgerId),
  2005. TaxGroupId: Number($(this).find(".hfProdTax").val())
  2006. });
  2007. }
  2008. }
  2009. });
  2010. $(".expense-row").each(function () {
  2011. if ($(this).find(".selectedItemId").val() != undefined) {
  2012. if ($(this).find(".hfSelectedChargeId").val() != "" && $(this).find(".hfSelectedChargeId").val() != "0") {
  2013. var invoicechargeid = $(this).find(".selectedInvoiceChargeId").val();
  2014. let ChargeId = $(this).find(".hfSelectedChargeId").val();
  2015. var chargeTypeId = $(this).find(".hdnChargeTypeId").val();
  2016. var percent = $(this).find(".exppercentage").val();
  2017. var value = $(this).find(".expfixedvalue").val();
  2018. var desc = $(this).find(".expenseDesc").val();
  2019. var totalamount = $(this).find(".expense-row-total").html();
  2020. var ledgerId = $(this).find(".hf_Account").val();
  2021. if (Number(value) != 0 || Number(percent)) {
  2022. ChargeList.push({
  2023. InvoiceChargeId: Number(invoicechargeid),
  2024. ChargeId: Number(ChargeId),
  2025. ChargeTypeId: Number(chargeTypeId),
  2026. Percentage: Number(percent),
  2027. FixedAmount: Number(value),
  2028. ApplyWhole: true,
  2029. Description: desc,
  2030. TotalAmount: Number(totalamount),
  2031. LedgerId: Number(ledgerId),
  2032. TaxGroupId: Number($(this).find(".hfProdTax").val())
  2033. });
  2034. }
  2035. }
  2036. }
  2037. });
  2038. return ChargeList;
  2039. }
  2040. getobj() {
  2041. var item = Number($(".selectedItemId").val());
  2042. var inventorytypeid = 0;
  2043. var AdjustmentAccountId = 0;
  2044. var isqtyavail = true;
  2045. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
  2046. Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItem(item).then(function (response) {
  2047. inventorytypeid = response.result.InventoryTypeId;
  2048. $(".InvoiceItems").find(".remove_item").remove();
  2049. InvoiceItem.Instance().update_total();
  2050. InvoiceItem.Instance().TotalAdjustment();
  2051. if ($("#chk_tcsapplied").prop("checked") == true && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && InvoiceItem.Instance().EnableTenantTcs == false) {
  2052. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2053. $(".InvoiceItems").append("<div class='item-row added-row InvoiceitemRow-0'></div>");
  2054. return false;
  2055. }
  2056. var CompanyName = $(".txtAutoComplete_orgcontactid").text();
  2057. if (CompanyName == "") {
  2058. $(".hfAutoCompleteId_orgcontactid").val(0);
  2059. }
  2060. var Adjustment = $('#txt_Adjustment').val();
  2061. if ($('#chk_AutoAdjustment').is(':checked')) {
  2062. if ($('#hf_AdjustmentAccountId').val() == 0) {
  2063. MessageHelper.Instance().showError("Please Select Adjustment Account", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2064. return false;
  2065. }
  2066. InvoiceItem.Instance().TotalAdjustment();
  2067. Adjustment = $('#txt_Adjustment').val();
  2068. AdjustmentAccountId = Number($("#txt_AdjustmentAccountName").val());
  2069. }
  2070. });
  2071. });
  2072. if ($('#chk_AutoAdjustment').is(':checked')) {
  2073. if ($('#hf_AdjustmentAccountId').val() == 0) {
  2074. MessageHelper.Instance().showError("Please Select Adjustment Account", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2075. return false;
  2076. }
  2077. else
  2078. AdjustmentAccountId = Number($("#txt_AdjustmentAccountName").val());
  2079. }
  2080. let isemptyrow = false;
  2081. let rownotexist = true;
  2082. let itemarray = [];
  2083. let emptysplitrow = false;
  2084. let itemname = "";
  2085. var IsUnitPriceZero = false;
  2086. $(".InvoiceItems").find(".item-addedrow").each(function () {
  2087. rownotexist = false;
  2088. if (!$(this).hasClass('SplitItem')) {
  2089. if ($(this).find(".selectedItemId").val() == undefined || $(this).find(".selectedItemId").val() == 0) {
  2090. isemptyrow = true;
  2091. }
  2092. if ($(this).find(".hfProdTax").val() == "0" || $(this).find(".hf_Account").val() == "0") {
  2093. itemarray.push($(this));
  2094. }
  2095. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && (InvoiceItem.Instance().AutoDc == true || InvoiceItem.Instance().OrderSettingId == 2)) {
  2096. inventorytypeid = Number($(this).find("#inventorytypeid").val());
  2097. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  2098. if ((Number($(this).find('.prodQuantity').val()) > Number($(this).find('.prodAvail').text())) && $(".hdn_invoiceid").val() == "0" && inventorytypeid != 2) {
  2099. isqtyavail = false;
  2100. }
  2101. else {
  2102. let Qty = Number($(this).find('.prodQuantity').val());
  2103. let AvQty = Number($(this).find('.prodAvail').text()) + Number($(this).find('.Qty').val());
  2104. if (Qty > AvQty && inventorytypeid != 2)
  2105. isqtyavail = false;
  2106. }
  2107. }
  2108. }
  2109. }
  2110. else {
  2111. if (InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.itemId == Number($(this).find(".selectedItemId").val()))) {
  2112. }
  2113. else {
  2114. emptysplitrow = true;
  2115. itemname = $(this).find(".prodName").text();
  2116. }
  2117. }
  2118. var UnitPrice = Number($(this).find(".prodPrice").val());
  2119. if (UnitPrice == 0 && $(this).find(".hf_IsBOM").val() == "false" && $(this).find(".hf_IsFoc").val() == "false") {
  2120. IsUnitPriceZero = true;
  2121. }
  2122. });
  2123. if (!isqtyavail) {
  2124. MessageHelper.Instance().showError("Please check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2125. return false;
  2126. }
  2127. if (isemptyrow) {
  2128. MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2129. return false;
  2130. }
  2131. if (rownotexist) {
  2132. MessageHelper.Instance().showError("Please Add Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2133. return false;
  2134. }
  2135. if (emptysplitrow) {
  2136. MessageHelper.Instance().showError("Please Select Mrp/Batch for the Item: " + itemname, $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2137. return false;
  2138. }
  2139. let couponitemrow = false;
  2140. $(".addednetdiscount-row").each(function () {
  2141. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  2142. if (($(this).find(".percentage").val() == "0" || $(this).find(".percentage").val() == "") && ($(this).find(".fixedvalue").val() == 0 || $(this).find(".fixedvalue").val() == ""))
  2143. isemptyrow = true;
  2144. }
  2145. if ($(this).find(".selectedItemId").val() == "0" || $(this).find(".selectedItemId").val() == undefined)
  2146. couponitemrow = true;
  2147. });
  2148. if (isemptyrow) {
  2149. MessageHelper.Instance().showError("Please enter percentage or value for coupon item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2150. return false;
  2151. }
  2152. let expenseitemrow = false;
  2153. $(".addedexpense-row").each(function () {
  2154. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  2155. if (($(this).find(".exppercentage").val() == "0" || $(this).find(".exppercentage").val() == "") && ($(this).find(".expfixedvalue").val() == 0 || $(this).find(".expfixedvalue").val() == ""))
  2156. isemptyrow = true;
  2157. }
  2158. if ($(this).find(".selectedItemId").val() == "0" || $(this).find(".selectedItemId").val() == undefined)
  2159. expenseitemrow = true;
  2160. });
  2161. if (isemptyrow) {
  2162. MessageHelper.Instance().showError("Please enter percentage or value for Expense Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2163. return false;
  2164. }
  2165. if (IsUnitPriceZero) {
  2166. MessageHelper.Instance().showError("Item UnitPrice should not be zero.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2167. return false;
  2168. }
  2169. if (couponitemrow) {
  2170. MessageHelper.Instance().showError("Please Select Coupon Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2171. return false;
  2172. }
  2173. if (expenseitemrow) {
  2174. MessageHelper.Instance().showError("Please Select Expense Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2175. return false;
  2176. }
  2177. var wallets = InvoiceItem.Instance().getwalletinvoiceditems();
  2178. var invItems = InvoiceItem.Instance().getInvoiceItems();
  2179. if (invItems.length == 0) {
  2180. MessageHelper.Instance().showError("You Should Add atleast One Item.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2181. return false;
  2182. }
  2183. else {
  2184. var qtyresult = invItems.find(x => x.AccountId == 0) ? true : false;
  2185. if (qtyresult == true) {
  2186. for (var i = 0; i < itemarray.length; i++) {
  2187. itemarray[i].find(".div_MoreDetails").removeClass("hidden");
  2188. }
  2189. MessageHelper.Instance().showError("Account Not Configured for the item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2190. return false;
  2191. }
  2192. var qty = invItems.find(x => x.Quantity == 0) ? true : false;
  2193. if (qty == true) {
  2194. MessageHelper.Instance().showError("Item quantity should not be zero.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2195. return false;
  2196. }
  2197. var TaxGroup = invItems.find(x => x.TaxGroupId == 0) ? true : false;
  2198. if (TaxGroup == true) {
  2199. for (var i = 0; i < itemarray.length; i++) {
  2200. itemarray[i].find(".div_MoreDetails").removeClass("hidden");
  2201. }
  2202. MessageHelper.Instance().showError("TaxGroup Not Configured for the item.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2203. return false;
  2204. }
  2205. }
  2206. var billingAddressId = $(".hfAutoCompleteId_billtoaddressid").val();
  2207. if (billingAddressId == null)
  2208. billingAddressId = $("#hfId_billtoaddressid").val();
  2209. var invoiceid = $(".hdn_invoiceid").val();
  2210. let refInvoiceId = 0;
  2211. if ($(".hdn_refinvoiceid").val() != undefined && Number($(".hdn_refinvoiceid").val()) != 0)
  2212. refInvoiceId = Number($(".hdn_refinvoiceid").val());
  2213. if (invoiceid == undefined)
  2214. invoiceid = 0;
  2215. if (($(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "3") && $("#hf_AppSettingName").val() == "Create Return") {
  2216. invoiceid = 0;
  2217. if (refInvoiceId == 0) {
  2218. refInvoiceId = Number($(".hdn_invoiceid").val());
  2219. $(".hdn_refinvoiceid").val($(".hdn_invoiceid").val());
  2220. }
  2221. $(".hdn_invoiceid").val("0");
  2222. $(".hdn_journalno").val("0");
  2223. }
  2224. let orgcontactid = $(".txtAutoComplete_orgcontactid").val();
  2225. var dcid = InvoiceItem.Instance().dcid;
  2226. if (invoiceid == 0 && ($(".hdn_invoicetypeid").val() == '3' || $(".hdn_invoicetypeid").val() == '4' || $(".hdn_invoicetypeid").val() == '7' || $(".hdn_invoicetypeid").val() == '6')) {
  2227. dcid = 0;
  2228. }
  2229. var orderid = InvoiceItem.Instance().orderid;
  2230. if (orderid == undefined || orderid == 0) {
  2231. orderid = 0;
  2232. }
  2233. var ClaimId = InvoiceItem.Instance().ClaimId;
  2234. if (ClaimId == undefined || ClaimId == 0) {
  2235. ClaimId = 0;
  2236. }
  2237. else
  2238. orderid = ClaimId;
  2239. var branchid = 0;
  2240. $(".txt_RefNo").val() == "null" ? $(".txt_RefNo").val("") : $(".txt_refno").val();
  2241. var description = $(".divCustomProperties_systemnotes").find("textarea").val();
  2242. if ($('.txt_tcsadjustment').val() == "")
  2243. $('.txt_tcsadjustment').val(0);
  2244. if (Number($(".nettotal").html()) < 0) {
  2245. MessageHelper.Instance().showError("Invoice value should not be less than 0", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2246. return false;
  2247. }
  2248. var InvoiceObject = {
  2249. TotalAmount: Number($(".nettotal").html()),
  2250. InvoiceItems: invItems,
  2251. InvoiceCharges: InvoiceItem.Instance().getCharges(),
  2252. AutoAdjustment: Boolean($('#chk_AutoAdjustment').is(':checked')),
  2253. AutoDc: InvoiceItem.Instance().AutoDc,
  2254. InvItemTaxAdjustments: InvoiceItem.Instance().invItemTaxAdjustmentList,
  2255. JournalAlloc: wallets,
  2256. AdjustmentAccountId: Number($("#txt_AdjustmentAccountName").val()),
  2257. InvoiceId: Number(invoiceid),
  2258. RefInvoiceId: Number(refInvoiceId),
  2259. OrgContactId: Number(orgcontactid),
  2260. DeletedInvoiceId: InvoiceItem.Instance().deleted_invoiceItems,
  2261. IsOfferChargeApplied: InvoiceItem.Instance().isOfferChargeApplied,
  2262. };
  2263. return InvoiceObject;
  2264. }
  2265. saveInvoice() {
  2266. $(".InvoiceItems").find(".remove_item").remove();
  2267. InvoiceItem.Instance().update_total();
  2268. InvoiceItem.Instance().TotalAdjustment();
  2269. var inventorytypeid = 0;
  2270. var AdjustmentAccountId = 0;
  2271. var item = Number($(".selectedItemId").val());
  2272. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
  2273. Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItem(item).then(function (response) {
  2274. inventorytypeid = response.result.InventoryTypeId;
  2275. if ($("#chk_tcsapplied").prop("checked") == true && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && InvoiceItem.Instance().EnableTenantTcs == false) {
  2276. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2277. $(".InvoiceItems").append("<div class='item-row added-row InvoiceitemRow-0'></div>");
  2278. return false;
  2279. }
  2280. var CompanyName = $(".txtAutoComplete_orgcontactid").text();
  2281. if (CompanyName == "") {
  2282. $(".hfAutoCompleteId_orgcontactid").val(0);
  2283. }
  2284. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && (InvoiceItem.Instance().AutoDc == true || InvoiceItem.Instance().OrderSettingId == 2)) {
  2285. var isqtyavail = true;
  2286. $(".InvoiceItems").find(".item-addedrow").each(function () {
  2287. if (!$(this).hasClass('SplitItem')) {
  2288. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  2289. if (Number($(this).find('.prodQuantity').val()) > Number($(this).find('.prodAvail').text()) && inventorytypeid != 2) {
  2290. isqtyavail = false;
  2291. }
  2292. }
  2293. }
  2294. });
  2295. if (!isqtyavail) {
  2296. MessageHelper.Instance().showError("Please check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2297. return false;
  2298. }
  2299. }
  2300. });
  2301. });
  2302. var Adjustment = $('#txt_Adjustment').val();
  2303. var AdjustmentAccountId = 0;
  2304. if ($('#chk_AutoAdjustment').is(':checked')) {
  2305. if ($('#hf_AdjustmentAccountId').val() == 0) {
  2306. MessageHelper.Instance().showError("Please Select Adjustment Account", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2307. return false;
  2308. }
  2309. InvoiceItem.Instance().TotalAdjustment();
  2310. Adjustment = $('#txt_Adjustment').val();
  2311. AdjustmentAccountId = Number($("#txt_AdjustmentAccountName").val());
  2312. }
  2313. if (Number($('#txt_Adjustment').val()) != 0) {
  2314. if ($('#hf_AdjustmentAccountId').val() == 0) {
  2315. MessageHelper.Instance().showError("Please Select Adjustment Account", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2316. return false;
  2317. }
  2318. else
  2319. AdjustmentAccountId = Number($("#txt_AdjustmentAccountName").val());
  2320. }
  2321. let isemptyrow = false;
  2322. let rownotexist = true;
  2323. let itemarray = [];
  2324. let emptysplitrow = false;
  2325. let itemname = "";
  2326. $(".InvoiceItems").find(".item-addedrow").each(function () {
  2327. rownotexist = false;
  2328. if (!$(this).hasClass('SplitItem')) {
  2329. if ($(this).find(".selectedItemId").val() == undefined || $(this).find(".selectedItemId").val() == 0) {
  2330. isemptyrow = true;
  2331. }
  2332. if ($(this).find(".hfProdTax").val() == "0" || $(this).find(".hf_Account").val() == "0") {
  2333. itemarray.push($(this));
  2334. }
  2335. }
  2336. else {
  2337. if (InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.itemId == Number($(this).find(".selectedItemId").val()))) {
  2338. }
  2339. else {
  2340. emptysplitrow = true;
  2341. itemname = $(this).find(".prodName").text();
  2342. }
  2343. }
  2344. });
  2345. if (isemptyrow) {
  2346. MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2347. return false;
  2348. }
  2349. if (rownotexist) {
  2350. MessageHelper.Instance().showError("Please Add Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2351. return false;
  2352. }
  2353. if (emptysplitrow) {
  2354. MessageHelper.Instance().showError("Please Select Mrp/Batch for the Item: " + itemname, $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2355. return false;
  2356. }
  2357. let couponitemrow = false;
  2358. $(".addednetdiscount-row").each(function () {
  2359. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  2360. if (($(this).find(".percentage").val() == "0" || $(this).find(".percentage").val() == "") && ($(this).find(".fixedvalue").val() == 0 || $(this).find(".fixedvalue").val() == ""))
  2361. isemptyrow = true;
  2362. }
  2363. if ($(this).find(".selectedItemId").val() == "0" || $(this).find(".selectedItemId").val() == undefined)
  2364. couponitemrow = true;
  2365. });
  2366. if (isemptyrow) {
  2367. MessageHelper.Instance().showError("Please enter percentage or value for coupon item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2368. return false;
  2369. }
  2370. if (couponitemrow) {
  2371. MessageHelper.Instance().showError("Please Select Coupon Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2372. return false;
  2373. }
  2374. let expenseitemrow = false;
  2375. $(".addedexpense-row").each(function () {
  2376. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  2377. if (($(this).find(".exppercentage").val() == "0" || $(this).find(".exppercentage").val() == "") && ($(this).find(".expfixedvalue").val() == 0 || $(this).find(".expfixedvalue").val() == ""))
  2378. isemptyrow = true;
  2379. }
  2380. if ($(this).find(".selectedItemId").val() == "0" || $(this).find(".selectedItemId").val() == undefined)
  2381. expenseitemrow = true;
  2382. });
  2383. if (isemptyrow) {
  2384. MessageHelper.Instance().showError("Please enter percentage or value for Expense Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2385. return false;
  2386. }
  2387. if (expenseitemrow) {
  2388. MessageHelper.Instance().showError("Please Select Expense Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2389. return false;
  2390. }
  2391. var wallets = InvoiceItem.Instance().getwalletinvoiceditems();
  2392. var invItems = InvoiceItem.Instance().getInvoiceItems();
  2393. if (invItems.length == 0) {
  2394. MessageHelper.Instance().showError("You Should Add atleast One Item.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2395. return false;
  2396. }
  2397. else {
  2398. var qtyresult = invItems.find(x => x.AccountId == 0) ? true : false;
  2399. if (qtyresult == true) {
  2400. for (var i = 0; i < itemarray.length; i++) {
  2401. itemarray[i].find(".div_MoreDetails").removeClass("hidden");
  2402. }
  2403. MessageHelper.Instance().showError("Account Not Configured for the item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2404. return false;
  2405. }
  2406. var qty = invItems.find(x => x.Quantity == 0) ? true : false;
  2407. if (qty == true) {
  2408. MessageHelper.Instance().showError("Item quantity should not be zero.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2409. return false;
  2410. }
  2411. var TaxGroup = invItems.find(x => x.TaxGroupId == 0) ? true : false;
  2412. if (TaxGroup == true) {
  2413. for (var i = 0; i < itemarray.length; i++) {
  2414. itemarray[i].find(".div_MoreDetails").removeClass("hidden");
  2415. }
  2416. MessageHelper.Instance().showError("TaxGroup Not Configured for the item.", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2417. return false;
  2418. }
  2419. }
  2420. var PaymentTermName = $(".txtAutoComplete_paymentiermid").text();
  2421. var billingAddressId = $(".hfAutoCompleteId_billtoaddressid").val();
  2422. if (billingAddressId == null)
  2423. billingAddressId = $("#hfId_billtoaddressid").val();
  2424. var invoiceid = $(".hdn_invoiceid").val();
  2425. let refInvoiceId = 0;
  2426. if (invoiceid == undefined)
  2427. invoiceid = 0;
  2428. if (($(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "3") && $("#hf_AppSettingName").val() == "Create Return") {
  2429. invoiceid = 0;
  2430. refInvoiceId = Number($(".hdn_invoiceid").val());
  2431. $(".hdn_refinvoiceid").val($(".hdn_invoiceid").val());
  2432. $(".hdn_invoiceid").val("0");
  2433. $(".hdn_journalno").val("0");
  2434. }
  2435. let orgcontactid = $(".txtAutoComplete_orgcontactid").val();
  2436. var dcid = InvoiceItem.Instance().dcid;
  2437. if (invoiceid == 0 && ($(".hdn_invoicetypeid").val() == '3' || $(".hdn_invoicetypeid").val() == '4' || $(".hdn_invoicetypeid").val() == '7' || $(".hdn_invoicetypeid").val() == '6')) {
  2438. dcid = 0;
  2439. }
  2440. var orderid = InvoiceItem.Instance().orderid;
  2441. if (orderid == undefined || orderid == 0) {
  2442. orderid = 0;
  2443. }
  2444. var ClaimId = InvoiceItem.Instance().ClaimId;
  2445. if (ClaimId == undefined || ClaimId == 0) {
  2446. ClaimId = 0;
  2447. }
  2448. else
  2449. orderid = ClaimId;
  2450. var branchid = 0;
  2451. if ((ClaimId != 0 || orderid != 0) && InvoiceItem.Instance().dcid == 0)
  2452. for (let obj of Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters) {
  2453. if (obj.Key === "hf_" + $("#hfLayout_InstalledPageId").val() + "_branchid")
  2454. branchid = InvoiceItem.Instance().orderid = Number(obj.Value);
  2455. }
  2456. else
  2457. branchid = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  2458. $(".txt_RefNo").val() == "null" ? $(".txt_RefNo").val("") : $(".txt_refno").val();
  2459. var description = $(".divCustomProperties_systemnotes").find("textarea").val();
  2460. if ($('.txt_tcsadjustment').val() == "")
  2461. $('.txt_tcsadjustment').val(0);
  2462. var InvoiceObject = {
  2463. PaymentTermName: PaymentTermName,
  2464. BranchId: branchid,
  2465. TotalAmount: Number($(".nettotal").html()),
  2466. InvoiceItems: invItems,
  2467. InvoiceCharges: InvoiceItem.Instance().getCharges(),
  2468. AutoAdjustment: Boolean($('#chk_AutoAdjustment').is(':checked')),
  2469. AutoDc: InvoiceItem.Instance().AutoDc,
  2470. InvItemTaxAdjustments: InvoiceItem.Instance().invItemTaxAdjustmentList,
  2471. JournalAlloc: wallets,
  2472. AdjustmentAccountId: Number($("#txt_AdjustmentAccountName").val()),
  2473. InvoiceId: Number(invoiceid),
  2474. RefInvoiceId: Number(refInvoiceId),
  2475. OrgContactid: orgcontactid,
  2476. DeletedInvoiceId: InvoiceItem.Instance().deleted_invoiceItems,
  2477. IsOfferChargeApplied: InvoiceItem.Instance().isOfferChargeApplied,
  2478. };
  2479. return InvoiceObject;
  2480. }
  2481. addRow() {
  2482. let isemptyrow = false;
  2483. $(".InvoiceItems").find(".item-addedrow").each(function () {
  2484. if (!$(this).hasClass('SplitItem')) {
  2485. if ($(this).find(".selectedItemId").val() == undefined || $(this).find(".selectedItemId").val() == 0) {
  2486. isemptyrow = true;
  2487. }
  2488. }
  2489. });
  2490. if (isemptyrow) {
  2491. MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  2492. return false;
  2493. }
  2494. var emptyRow = {
  2495. orderItemId: 0,
  2496. invoiceItemId: 0,
  2497. itemName: "",
  2498. itemId: 0,
  2499. itemSKU: "",
  2500. unitName: "",
  2501. packSize: 0,
  2502. packCount: 0,
  2503. packs: 0,
  2504. quantity: 0,
  2505. availPacks: 0,
  2506. availQty: 0,
  2507. listPrice: 0,
  2508. description: "",
  2509. taxGroupName: "",
  2510. taxGroupId: 0,
  2511. isTaxInclusive: $("#hf_istaxinclusive").val(),
  2512. addlDiscountPercent: 0,
  2513. addlDiscountValue: 0,
  2514. creditNote: 0,
  2515. priceListId: 0,
  2516. batchId: 0,
  2517. unitPrice: 0,
  2518. invoiceallocations: null,
  2519. exciseInvoiceItem: null,
  2520. accountId: 0,
  2521. accountName: "",
  2522. walletId: 0,
  2523. Adjustment: 0,
  2524. IsFoc: false,
  2525. TariffNo: "",
  2526. exciseAmount: 0,
  2527. discountName: "",
  2528. discountId: 0,
  2529. refNo: "",
  2530. DiscountGroupId: 0,
  2531. DiscountGroupName: '',
  2532. RefInvoiceItemId: 0,
  2533. MrpId: 0,
  2534. taxAdjustment: 0,
  2535. assesableAdjustment: 0,
  2536. inventoryTypeId: 0,
  2537. dcItemId: 0,
  2538. TotalRowAmount: 0,
  2539. maxQty: 0,
  2540. OfferItemId: 0
  2541. };
  2542. InvoiceItem.instance.addDataRow(emptyRow, false);
  2543. }
  2544. addDataRow(row, IsSplitItem) {
  2545. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("tenants/themes/compact/components/details/details.js", function () {
  2546. });
  2547. this.rowIndex = $(".InvoiceItems").find(".item-addedrow").length + 1;
  2548. var bg = "";
  2549. if (row.packSize == 0)
  2550. row.packSize = 1;
  2551. if (row.packCount == 0)
  2552. row.packCount = 1;
  2553. if (row.quantity == 0)
  2554. row.quantity = row.packCount * row.packs * row.packSize;
  2555. var price = row.unitPrice;
  2556. if (row.unitPrice == 0)
  2557. price = row.listPrice;
  2558. var currenttaxgroupid = 0;
  2559. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_IsRetun').val() == "1") {
  2560. row.invoiceallocations = null;
  2561. row.invoiceItemId = 0;
  2562. }
  2563. if ($('#hfInv_IsRetun').val() == "1")
  2564. row.invoiceItemId = 0;
  2565. var zeroBilled = "";
  2566. if (price == 0)
  2567. zeroBilled = "bg-danger";
  2568. var zeroQtyText = "";
  2569. var zeroQtyDiv = "bg-light";
  2570. let invoiceid = $(".hdn_invoiceid").val();
  2571. if (invoiceid == "0") {
  2572. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && row.itemId != 0 && row.IsFoc == false) {
  2573. if (row.availQty == 0) {
  2574. row.quantity = 0;
  2575. zeroQtyText = "text-danger";
  2576. zeroQtyDiv = "bg-danger";
  2577. }
  2578. else if (row.availQty < row.quantity) {
  2579. row.quantity = row.availQty;
  2580. }
  2581. }
  2582. }
  2583. var readonlyQty = "";
  2584. var ManageInvoice = 2;
  2585. var AutoDc = false;
  2586. var ManageInvoiceTax = 2;
  2587. var readonlyPrice = "";
  2588. var readonlyDisc = "";
  2589. var readonlyTax = "";
  2590. if (ManageInvoice == 1 && AutoDc == false) {
  2591. readonlyQty = "readonly";
  2592. readonlyPrice = "readonly";
  2593. readonlyDisc = "readonly";
  2594. readonlyTax = "disabled";
  2595. }
  2596. if ($('.hdn_invoicetypeid').val() == "1" && ManageInvoiceTax == 1 && AutoDc == false) {
  2597. readonlyTax = "readonly";
  2598. }
  2599. if (row.inventoryTypeId == "2") {
  2600. readonlyQty = "";
  2601. readonlyPrice = "";
  2602. }
  2603. var activeDiscVal = "";
  2604. var activeDiscPercent = "";
  2605. var activeDiscMul = "";
  2606. var activeDiscText = "";
  2607. var discValue = 0;
  2608. if (row.addlDiscountPercent > 0) {
  2609. discValue = row.addlDiscountPercent;
  2610. activeDiscPercent = "active";
  2611. activeDiscText = "%";
  2612. }
  2613. else if (row.addlDiscountValue > 0 && row.DiscountGroupId > 0) {
  2614. discValue = row.addlDiscountValue;
  2615. activeDiscMul = "active";
  2616. activeDiscText = "Mul";
  2617. }
  2618. else {
  2619. discValue = row.addlDiscountValue;
  2620. activeDiscVal = "active";
  2621. activeDiscText = "Val";
  2622. }
  2623. var itemNameClass = "floating-label-form-group";
  2624. if (row.invoiceItemId != 0)
  2625. itemNameClass = "";
  2626. var mt = "";
  2627. if (row.invoiceItemId != 0) {
  2628. mt = "mt-5";
  2629. }
  2630. if (row.orderItemId != 0) {
  2631. mt = "mt-10";
  2632. }
  2633. let AlternateUnitId = row.AlternateUnitId;
  2634. let DefaultSize = row.DefaultSize;
  2635. if (AlternateUnitId == undefined) {
  2636. AlternateUnitId = 0;
  2637. }
  2638. if (row.ParentBOMItemId == null)
  2639. row.ParentBOMItemId = 0;
  2640. if (row.inventoryTypeId != 5 && row.inventoryTypeId != 6 && row.inventoryTypeId != 7) {
  2641. var IsBom = "";
  2642. if (row.IsBoMItem == true && row.IsBoMItem != undefined) {
  2643. IsBom = "hidden";
  2644. }
  2645. var isbomitem = false;
  2646. if (row.ParentBOMItemId != 0)
  2647. isbomitem = true;
  2648. var html = '<div id="div_itemAddedRow_' + this.rowIndex + '" class="item-row item-addedrow ' + bg + '">' +
  2649. '<div class="row mx-0 justify-content-between align-items-end ' + IsBom + ' divItemRow_' + row.itemId + ' ">' +
  2650. '<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>' +
  2651. '<div class=" item-name min-padding" style="margin-left:20px;">' +
  2652. '<lable for="lbl_itemname" class="d-md-none">Item Name</lable>' +
  2653. '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  2654. '<input type="hidden" class="orderItemId" value="' + row.orderItemId + '" />' +
  2655. '<input type="hidden" class="dcItemId" value="' + row.dcItemId + '" />' +
  2656. '<input type="hidden" class="selectedInvoiceItemId" value="' + row.invoiceItemId + '" />' +
  2657. '<input type="hidden" class="refInvoiceItemId" value="' + row.RefInvoiceItemId + '" />' +
  2658. '<input type="hidden" class="selectedItemId" id="hf_txtitem_' + this.rowIndex + '" value="' + row.itemId + '" />' +
  2659. '<input type="hidden" id="selectedItemId" value="' + row.itemId + '" />' +
  2660. '<input type="hidden" id="inventorytypeid" value="' + row.itemId + '" />' +
  2661. '<input type="hidden" class="selectedItemName" value="' + row.itemname + '" />' +
  2662. '<input type="hidden" class="hfMrpId" value="' + row.MrpId + '" />' +
  2663. '<input type="hidden" class="offerapplied" value="0" />' +
  2664. '<input type="hidden" class="refNo" value="' + row.refNo + '"/>' +
  2665. '<input type="hidden" class="description" value="' + row.description + '"/>' +
  2666. '<input type="hidden" class="IsExchangeItem" value="' + row.ExchangeItem + '" />' +
  2667. '<input type="hidden" class="maxQty" value="' + row.maxQty + '" />' +
  2668. '<input type="hidden" class="Qty" value="' + row.quantity + '" />' +
  2669. '<input type="hidden" class="hfAccountId" value="' + row.accountId + '"/>' +
  2670. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="' + row.taxAdjustment + '" />' +
  2671. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="' + row.assesableAdjustment + '" />' +
  2672. '<input type="hidden" class="hfoldItemId" value="' + row.itemId + '"/>' +
  2673. '<input type="hidden" class="hf_IsFoc" value="' + row.IsFoc + '"/>' +
  2674. '<input type="hidden" class="hf_UnitPrice" value="' + price + '"/>' +
  2675. '<input type="hidden" class="hf_AlternateUnitId" value="' + AlternateUnitId + '"/>' +
  2676. '<input type="hidden" class="hf_AlternateUnitName" value="' + row.AlternateUnitName + '"/>' +
  2677. '<input type="hidden" class="hf_UnitName" value="' + row.unitName + '"/>' +
  2678. '<input type="hidden" class="hf_DefaultSize" value="' + DefaultSize + '"/>' +
  2679. '<input type="hidden" class="hf_IsBOM" value="' + isbomitem + '"/>' +
  2680. '<input type="hidden" class="hf_ParentBOMItemId" value="' + row.ParentBOMItemId + '"/>' +
  2681. '<input type="hidden" class="hf_IsMultipleUOM" value="' + row.IsMultipleUOMs + '"/>' +
  2682. '<input type="hidden" class="hf_IsManualUOM" value="' + row.IsManualUOM + '"/>' +
  2683. '<input type="hidden" class="hf_ConversionQuantity" value="' + row.ConversionQuantity + '"/>' +
  2684. '<input type="hidden" class="hf_IsSpecialPrice" value="' + row.IsSpecialPrice + '"/>' +
  2685. '<input type="hidden" class="hf_AddtionalDiscount" value="0"/>';
  2686. if (row.IsFoc == true) {
  2687. html += '<input type="hidden" class="hfOfferedItemId" value="' + row.OfferItemId + '"/>';
  2688. }
  2689. html += '<div class="item-name-wrap">' +
  2690. '<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>';
  2691. if (row.invoiceItemId != 0) {
  2692. var itemName = row.itemSKU + ' - ' + row.itemName;
  2693. if (row.ExchangeItem)
  2694. itemName = '(Exchange) ' + row.itemSKU + ' - ' + row.itemName;
  2695. html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
  2696. }
  2697. else {
  2698. var itemName = "";
  2699. if (row.ExchangeItem)
  2700. itemName = '(Exchange) ' + row.itemName;
  2701. else if (row.itemName != "" && row.itemSKU != "") {
  2702. itemName = row.itemSKU + '-' + row.itemName;
  2703. html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
  2704. }
  2705. else if (row.itemName != "") {
  2706. itemName = row.itemName;
  2707. html += '<a class="default prodName-link mt-10 ItemName" href="javascript:;">' + itemName + '</a>';
  2708. }
  2709. else {
  2710. html += '<select class="form-control prodName" value="" id="txt_item_' + this.rowIndex + '" placeholder=" Select the item to Invoice" style="width:100%;" id="txtItem"></select>';
  2711. }
  2712. }
  2713. html += '</div>' +
  2714. '</div></div>' +
  2715. '<div class="col-lg-2 col-md-6 pr-0 my-15">' +
  2716. '<div class="floating-label-form-group text-center border-left-0">' +
  2717. '<lable for="lbl_qty" class="d-md-none">Qty</lable>' +
  2718. '<input type="text" class="prodQuantity text-center ' + zeroQtyText + ' form-control" placeholder="0.00" inputmode="numeric" value="' + row.quantity + '" ' + readonlyQty + ' />' +
  2719. '</div>' +
  2720. '</div>' +
  2721. '<div class="col-lg-2 col-md-4 div_UnitPrice my-15">' +
  2722. '<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>';
  2723. var readonly = "";
  2724. html += '<input type="text" class="prodPrice text-center form-control" placeholder="0.00" inputmode="numeric" value="' + price + '" ' + readonlyPrice + ' />';
  2725. html += '</div></div>' +
  2726. '<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>' +
  2727. '<div class="col-lg-2 col-md-4 my-15 div_Discount"> ' +
  2728. '<div class="floating-label-form-group text-center">' +
  2729. '<lable for="lbl_disc" class="d-md-none">Disc.</lable>' +
  2730. '<input type="hidden" id="hfProdDiscountGroupId" value="' + row.DiscountGroupId + '" />' +
  2731. '<input type="hidden" id="hfProdDiscountGroupName" value="' + row.DiscountGroupName + '" />' +
  2732. '<input type="hidden" id="hfProdDiscountList" value="" />' +
  2733. '<input type="hidden" id="hfProdDiscountApplyTypes" value="" />' +
  2734. '<div class="input-group">' +
  2735. '<input type="text" id="inv_txtdiscount" placeholder="0.00" class="form-control inv_txtaddldiscount" inputmode="numeric" value="' + discValue + '" ' + readonlyDisc + '>' +
  2736. '<div class="input-group-btn">' +
  2737. '<select class="btnInvoice_DiscType btn_inv_DiscType mt-10 border-blue"><option value="Val">Val</option><option value="%">%</option></select>' +
  2738. '</div>' +
  2739. '</div>' +
  2740. '</div>' +
  2741. '</div>' +
  2742. '<div class="col-lg-2 col-md-4 my-15">' +
  2743. '<input type="hidden" class="hfDiscountedAmount" value="0" />' +
  2744. '<input type="hidden" class="hfRowTotalAdjustment" value="' + row.Adjustment + '" />' +
  2745. '<input type="hidden" class="hfAssesableAdjustment" value="" />' +
  2746. '<input type="hidden" class="hfTaxAdjustment" value="" />';
  2747. if (($(".hdn_invoicetypeid").val() == "2") && invoiceid != 0) {
  2748. 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>';
  2749. 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>';
  2750. }
  2751. else {
  2752. 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>';
  2753. }
  2754. html += '</div>' +
  2755. '</div>' +
  2756. '<div class="row"> <span class="col-sm-4"> <p class="ml-35 text-warning ItemConversion"> </p> </span>' +
  2757. '<span class="col-sm-2 text-center SelectedUOMName pl-50"> </span>' +
  2758. '<span class="col-sm-6 text-right UOMCalc"> </span></div>' +
  2759. '<div class="hidden div_MoreDetails clear mt-5 bg-light">' +
  2760. '<div class="row align-items-center mx-5 pt-10">' +
  2761. '<div class="col-lg-2 col-md-4 my-15">' +
  2762. '<div class="floating-label-form-group Desc">' +
  2763. '<label for="from_lbl_Description" id="lbl_Description">Description</label>' +
  2764. '<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"/>' +
  2765. '</div>' +
  2766. '</div>' +
  2767. '<div class="col-lg-2 col-md-4 my-15 hidden" id="div_MultipleUOMs">' +
  2768. '<div class="floating-label-form-group-with-value">' +
  2769. '<label for="from_lbl_UOM" id="lbl_Output">UOM</label>' +
  2770. '<div class="input-group">' +
  2771. '<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>' +
  2772. '</div></div>' +
  2773. '</div>' +
  2774. '<div class="col-lg-2 col-md-4 my-15">' +
  2775. '<div class="floating-label-form-group-with-value">' +
  2776. '<label for="from_lbl_Output" id="lbl_Output">Tax Group<span class="text-danger">*</span></label>' +
  2777. '<div class="input-group">';
  2778. if (row.taxGroupId != 0) {
  2779. 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>' +
  2780. '<input type="hidden" id="hfProdTaxPercent_' + this.rowIndex + '" class="hfProdTaxPercent" value="0" />' +
  2781. '<input type="hidden" id="hfProdTax_' + this.rowIndex + '" class="hfProdTax hidden" value="' + row.taxGroupId + '"/>' +
  2782. '<input type="hidden" class="txtProdTax hidden" value="' + row.taxGroupName + '"/>';
  2783. }
  2784. else {
  2785. 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>' +
  2786. '<input type="hidden" id="hfProdTaxPercent_' + this.rowIndex + '" class="hfProdTaxPercent" value="0" />' +
  2787. '<input type="hidden" id="hfProdTax_' + this.rowIndex + '" class="hfProdTax hidden" value="0"/>' +
  2788. '<input type="hidden" class="txtProdTax hidden" value=""/>';
  2789. }
  2790. html += '</div>' +
  2791. '</div>' +
  2792. '</div>' +
  2793. '<div class="col-lg-3 col-md-4 my-15">' +
  2794. '<div class="floating-label-form-group-with-value">' +
  2795. '<label for="from_lbl_Account" id="lbl_Account">Account<span class="text-danger">*</span></label>';
  2796. if (row.accountId != 0) {
  2797. 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>' +
  2798. '<input type="hidden" id="hf_Account_' + this.rowIndex + '" class="hf_Account" value="' + row.accountId + '" />' +
  2799. '<input type="hidden" id="txt_AccountName_' + this.rowIndex + '" class="txt_AccountName" value="' + row.accountName + '"/>';
  2800. }
  2801. else {
  2802. 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>' +
  2803. '<input type="hidden" id="hf_Account_' + this.rowIndex + '" class="hf_Account" value="0" />' +
  2804. '<input type="hidden" id="txt_AccountName_' + this.rowIndex + '" class="txt_AccountName" value=""/>';
  2805. }
  2806. html += '</div>' +
  2807. '</div>' +
  2808. '<div class="col-lg-3 col-auto align-seld-end ml-auto text-right">' +
  2809. '<label for="from_lbl_Avalilability" id="lbl_Avalilability" class="text-dark mb-0 font-weight-bold mr-10">Availability :</label>' +
  2810. '<span class="prodAvail">' + row.availQty + '</span>' +
  2811. '</div>' +
  2812. '</div>' +
  2813. '<div class="row ml-5 mr-5">' +
  2814. '<div class="col-md-2"> </div>' +
  2815. '</div>' +
  2816. '<div class="row">' +
  2817. '<div class="col-md-12">' +
  2818. '<div class="col-md-3 form-group div_Mrp hidden">' +
  2819. '<div class="floating-label-form-group floating-label focus">' +
  2820. '<input type="hidden" class="hf_PriceList" value="' + row.priceListId + '" />' +
  2821. '<label for="from_lbl_MRP" id="lbl_MRP">MRP</label>' +
  2822. '<input type="text" data-isdynamic="false" class="form-control floating-label-control txt_MRP" data-placeholder="53" placeholder="MRP" data-label="MRP" />' +
  2823. '</div>' +
  2824. '</div>' +
  2825. '</div>' +
  2826. '<div class="orderitemlist"></div>' +
  2827. '</div><div class="accountRow"></div>';
  2828. $(".item-row:last").after(html);
  2829. var element = $(".item-addedrow:last");
  2830. if (IsSplitItem == true) {
  2831. element.addClass('SplitItem');
  2832. }
  2833. InvoiceItem.Instance().loadTaxGroupAutoComplete(element);
  2834. if (row.IsMultipleUOMs && $(".hdn_invoicetypeid").val() == "1") {
  2835. let MultipleUOMs = row.MultipleUoms;
  2836. let html = '<option value="0"> -- Select -- </option>';
  2837. for (var i = 0; i < MultipleUOMs.length; i++) {
  2838. html += '<option value="' + MultipleUOMs[i].SchemaDetailId + '">' + MultipleUOMs[i].AlternateUnitName + ' ( ' + MultipleUOMs[i].DefaultSize + ' ' + MultipleUOMs[i].DefaultUnitName + ' ) </option>';
  2839. }
  2840. element.find(".ddl_MultipleUOMs").html(html);
  2841. element.find("#div_MultipleUOMs").removeClass("hidden");
  2842. InvoiceItem.Instance().UOMs.push({
  2843. ItemId: row.itemId,
  2844. MultipleUOMs: MultipleUOMs
  2845. });
  2846. let SelectedUOM = Number(element.find(".hf_AlternateUnitId").val());
  2847. let DefaultSize = Number(element.find(".hf_DefaultSize").val());
  2848. if (SelectedUOM != 0) {
  2849. element.find(".ddl_MultipleUOMs").val(SelectedUOM);
  2850. let Qty = Number(element.find(".prodQuantity").val());
  2851. let NewQty = Qty / DefaultSize;
  2852. element.find(".prodQuantity").val(NewQty);
  2853. }
  2854. }
  2855. var txtTaxGroup = element.find(".prodTax");
  2856. var hfProdTax = element.find(".hfProdTax");
  2857. var hfAccount = element.find(".hf_Account");
  2858. var txtAccount = element.find(".txt_Account");
  2859. hfAccount.val(row.accountId);
  2860. hfProdTax.val(row.taxGroupId);
  2861. txtTaxGroup.append(new Option(row.taxGroupName, row.taxGroupId, true));
  2862. txtAccount.append(new Option(row.accountName, row.accountId, true));
  2863. InvoiceItem.instance.itemsAutoComplete(element);
  2864. InvoiceItem.instance.itemChange(element, element.find(".prodName").val(), element.find(".selectedItemId"));
  2865. $('.inv_txtaddldiscount').keypress(function (event) {
  2866. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  2867. if (element.find(".selectedItemId").val() == "0") {
  2868. Unibase.Platform.Forms.Components.FormViewer.Instance().showError("Please Select Item");
  2869. element.find('.inv_txtaddldiscount').val(0);
  2870. }
  2871. }
  2872. else {
  2873. event.preventDefault();
  2874. }
  2875. }).on('paste', function (event) {
  2876. var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
  2877. let val = event.originalEvent["clipboardData"].getData('text');
  2878. if (!numberRegex.test(val)) {
  2879. event.preventDefault();
  2880. return false;
  2881. }
  2882. });
  2883. $('.prodQuantity').keypress(function (event) {
  2884. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  2885. if (element.find(".selectedItemId").val() == "0") {
  2886. Unibase.Platform.Forms.Components.FormViewer.Instance().showError(" Please Select Item");
  2887. element.find(".prodQuantity").val(0);
  2888. }
  2889. }
  2890. else {
  2891. event.preventDefault();
  2892. }
  2893. }).on('paste', function (event) {
  2894. var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
  2895. let val = event.originalEvent["clipboardData"].getData('text');
  2896. if (!numberRegex.test(val)) {
  2897. event.preventDefault();
  2898. return false;
  2899. }
  2900. });
  2901. $('.prodPrice').keypress(function (event) {
  2902. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  2903. if (element.find(".selectedItemId").val() == "0") {
  2904. Unibase.Platform.Forms.Components.FormViewer.Instance().showError(" Please Select Item");
  2905. element.find('.prodPrice').val(0);
  2906. }
  2907. }
  2908. else {
  2909. event.preventDefault();
  2910. }
  2911. }).on('paste', function (event) {
  2912. var numberRegex = /^\s*[+-]?(\d+|\d*\.\d+|\d+\.\d*)([Ee][+-]?\d+)?\s*$/;
  2913. let val = event.originalEvent["clipboardData"].getData('text');
  2914. if (!numberRegex.test(val)) {
  2915. event.preventDefault();
  2916. return false;
  2917. }
  2918. });
  2919. element.find(".btnInvoice_DiscType option[value='" + activeDiscText + "']").prop("selected", true);
  2920. element.find(".prodPrice,.prodQuantity,.inv_txtaddldiscount").focusin(function () {
  2921. if (element.find($(".prodName")).val() != null || element.find($(".ItemName")).val() != null) {
  2922. $(".div_MoreDetails").addClass("hidden");
  2923. if (!element.parents(".item-row").hasClass('SplitItem'))
  2924. element.find(".div_MoreDetails").removeClass("hidden");
  2925. }
  2926. });
  2927. element.find(".prodName").focusin(function () {
  2928. $(".divMoreDetails").addClass("hidden");
  2929. });
  2930. if (row.description != null && row.description != '' && row.description != 'null') {
  2931. element.find('#txt_Description').val(row.description);
  2932. element.find('#txt_Description').parent(".Desc").addClass("floating-label-form-group-with-value");
  2933. }
  2934. InvoiceItem.Instance().bind(element, row.inventoryTypeId);
  2935. element.find("#inv_txtdiscount").change(function () {
  2936. if (!element.hasClass('SplitItem')) {
  2937. if (element.find(".btnInvoice_DiscType").val() == "%") {
  2938. if (Number(element.find("#inv_txtdiscount").val()) > 100) {
  2939. element.find("#inv_txtdiscount").val("100");
  2940. }
  2941. }
  2942. }
  2943. });
  2944. if (row.TotalRowAmount != 0) {
  2945. if ($(".hdn_invoicetypeid").val() == "2") {
  2946. element.find(".hfRowTotalwithAdjustment").val();
  2947. element.find(".hfRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(row.TotalRowAmount), 2));
  2948. if (element.hasClass('SplitItem'))
  2949. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalRowAmount, 2));
  2950. }
  2951. else {
  2952. element.find('.prodTotalPrice').text('');
  2953. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalRowAmount, 2));
  2954. }
  2955. }
  2956. if (row.TotalDiscount != 0 && row.TotalDiscount != undefined)
  2957. element.find('#inv_txtdiscount').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(row.TotalDiscount, 2));
  2958. if (row.invoiceItemId != "0" && ($(".hdn_invoicetypeid").val() == "2")) {
  2959. var x = element.find('.hfRowTotalwithAdjustment');
  2960. element.find('.AdjustmentRow').click(function () {
  2961. InvoiceItem.Instance().editInvItemTaxAllocs(row.invoiceItemId, row.taxGroupId, row.itemId, row.orderItemId, element);
  2962. });
  2963. }
  2964. if (row.IsFoc == true) {
  2965. element.find('.delete').addClass('hidden');
  2966. element.find('.prodQuantity').prop('readonly', 'readonly');
  2967. element.find('.prodPrice').prop('readonly', 'readonly');
  2968. element.find("#inv_txtdiscount").prop('readonly', 'readonly');
  2969. element.find(".btnInvoice_DiscType").prop('disabled', true);
  2970. element.find('.prodQuantity').css('cursor', 'not-allowed');
  2971. element.find('.prodPrice').css('cursor', 'not-allowed');
  2972. element.find("#inv_txtdiscount").css('cursor', 'not-allowed');
  2973. }
  2974. }
  2975. else {
  2976. var element = $(".discount-addedrow:last");
  2977. if (row.inventoryTypeId == 5) {
  2978. element = $(".netdiscount-addedrow:last");
  2979. InvoiceItem.Instance().adddiscountrow(row, row.itemName, row.itemId, true);
  2980. }
  2981. if (row.inventoryTypeId == 6) {
  2982. InvoiceItem.Instance().adddiscountrow(row, row.itemName, row.itemId, false);
  2983. }
  2984. if (row.inventoryTypeId == 7) {
  2985. InvoiceItem.Instance().addExpenseRow(row, row.itemName, row.itemId, true);
  2986. }
  2987. }
  2988. }
  2989. loadTaxGroupAutoComplete(element) {
  2990. var txtTaxGroup = element.find(".prodTax");
  2991. var hfProdTax = element.find(".hfProdTax");
  2992. var hfAccount = element.find(".hf_Account");
  2993. var txtAccount = element.find(".txt_Account");
  2994. var accid = element.find(".hf_Account").val();
  2995. var taxgrpid = element.find(".hfProdTax").val();
  2996. var taxgrptext = element.find(".txtProdTax").val();
  2997. var acctext = element.find(".txt_AccountName").val();
  2998. var applytype = "Sales";
  2999. AutoCompleteHelper.getHelper().Create("#txt_prodTax_" + this.rowIndex, hfProdTax, _appsettings.server_url() + "/apis/v4/bizgaze/transact/tax/taxgroupautocomplete", function (result) {
  3000. if (hfProdTax.val() != '')
  3001. InvoiceItem.Instance().update_tax(element, hfProdTax.val());
  3002. });
  3003. var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/ledgers/ledgerautocomplete';
  3004. const selectId = `#txt_Account_${this.rowIndex}`;
  3005. AutoCompleteHelper.getHelper().Create(selectId, hfAccount, url, function (response) {
  3006. $(selectId).off('select2:open').on('select2:open', (e) => {
  3007. const dropdownEl = $($(e.currentTarget).data('select2').$dropdown);
  3008. dropdownEl.addClass('select2-account-container');
  3009. });
  3010. });
  3011. }
  3012. update_total() {
  3013. var totalAmount = 0;
  3014. var totalDiscountAmount = 0;
  3015. var totalNonDiscountedAmount = 0;
  3016. var totalTaxAmount = 0;
  3017. var totalTaxAdjustment = 0;
  3018. var totalAsseableAdjustment = 0;
  3019. var totalQty = 0;
  3020. var totalDiscountPercent = 0;
  3021. var totalDiscountValue = 0;
  3022. var totalAddlDiscountPercent = 0;
  3023. var totalAddlDiscountValue = 0;
  3024. var totalExpensePercent = 0;
  3025. var totalExpenseValue = 0;
  3026. var addexpenserow_total = 0;
  3027. $('.expense-row-total').each(function (i) {
  3028. var expense_row_total = Number($(this).html());
  3029. addexpenserow_total += expense_row_total;
  3030. });
  3031. var ConsumedWalletValue = 0;
  3032. var totalTaxPercent = 0;
  3033. var totalTaxValue = 0;
  3034. var totalCreditNote = 0;
  3035. var adddiscountrow_total = 0;
  3036. var netadddiscountrow_total = ConsumedWalletValue;
  3037. $('.discount-row-total').each(function (i) {
  3038. var discount_row_total = Number($(this).html());
  3039. adddiscountrow_total += discount_row_total;
  3040. });
  3041. $('.netdiscount-row-total').each(function (i) {
  3042. var discount_row_total = Number($(this).html());
  3043. netadddiscountrow_total += discount_row_total;
  3044. });
  3045. var itemdiscount_total = 0;
  3046. var totalLineAmount_total = 0;
  3047. $('.hfRowTotal').each(function (i) {
  3048. var element = $(this).parents(".item-row");
  3049. if (!element.hasClass('SplitItem')) {
  3050. var totalLineAmount = Number($(this).val());
  3051. if (!isNaN(totalLineAmount))
  3052. totalLineAmount_total += Number(totalLineAmount);
  3053. var discountPercent = 0;
  3054. var discountValue = 0;
  3055. var quantity = Number(element.find(".prodQuantity").val());
  3056. var unitPrice = Number(element.find(".prodPrice").val());
  3057. var exciseAmount = Number(element.find(".exciseAmount").val());
  3058. if (isNaN(exciseAmount))
  3059. exciseAmount = 0;
  3060. var nonexciseAmount = totalLineAmount - exciseAmount;
  3061. if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Val' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
  3062. discountValue = Number(element.find('.inv_txtaddldiscount').val());
  3063. }
  3064. else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == '%' && element.find('.inv_txtaddldiscount').val() != '' && element.find('.inv_txtaddldiscount').val() != undefined) {
  3065. discountPercent = Number(element.find('.inv_txtaddldiscount').val());
  3066. }
  3067. else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Mul') {
  3068. if (element.find('#hfProdDiscountList').val() != '' || element.find('#hfProdDiscountApplyTypes').val() != '') {
  3069. var discountsArray = element.find('#hfProdDiscountList').val().toString().split(',');
  3070. var applyTypes = element.find('#hfProdDiscountApplyTypes').val().toString().split(',');
  3071. var price = Number(unitPrice) * Number(quantity);
  3072. var currentAmount = Number(unitPrice) * Number(quantity);
  3073. $.each(discountsArray, function (j) {
  3074. var percent = discountsArray[j];
  3075. var applyType = applyTypes[j];
  3076. var discount = 0;
  3077. if (applyType == 'NET' || applyType == '1') {
  3078. discount = Number(price) * Number(percent) / 100;
  3079. currentAmount -= Number(discount);
  3080. }
  3081. else {
  3082. discount = Number(currentAmount) * Number(percent) / 100;
  3083. currentAmount -= Number(discount);
  3084. }
  3085. discountValue += Number(discount);
  3086. });
  3087. element.find('.inv_txtaddldiscount').val(discountValue);
  3088. }
  3089. else {
  3090. discountValue = Number(element.find('.inv_txtaddldiscount').val());
  3091. }
  3092. }
  3093. if (!isNaN(discountPercent))
  3094. totalDiscountPercent += Number(discountPercent);
  3095. if (!isNaN(discountValue))
  3096. totalAddlDiscountValue += Number(discountValue);
  3097. var discountAmount = 0;
  3098. discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
  3099. + (Number(quantity) * Number(discountValue));
  3100. if ($(".hdn_invoicetypeid").val() == "1" && (element.find(".hf_IsManualUOM").val() == "true" || element.find(".hf_IsMultipleUOM").val() == "true")) {
  3101. let ConversionQuantity = Number(element.find(".hf_ConversionQuantity").val());
  3102. if (ConversionQuantity > 0)
  3103. discountAmount = (Number(nonexciseAmount) * Number(discountPercent) / 100)
  3104. + (Number(ConversionQuantity) * Number(discountValue));
  3105. }
  3106. discountAmount = Number(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(discountAmount, 2));
  3107. itemdiscount_total += discountAmount;
  3108. var discountedAmount = Number(totalLineAmount) - Number(discountAmount);
  3109. totalDiscountAmount += Number(discountAmount);
  3110. element.find(".hfDiscountedAmount").val(discountAmount);
  3111. let invoiceid = $(".hdn_invoiceid").val();
  3112. if (invoiceid == undefined || invoiceid == "null")
  3113. invoiceid = 0;
  3114. if (($(".hdn_invoicetypeid").val() == "2") && invoiceid != 0) {
  3115. element.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2));
  3116. element.find(".prodTotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2).toString());
  3117. }
  3118. else
  3119. element.find(".prodTotalPrice").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalLineAmount - discountAmount, 2).toString());
  3120. }
  3121. });
  3122. if (InvoiceItem.Instance().SplitedInvoiceItemList.length > 0) {
  3123. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  3124. var totalline_Amount = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
  3125. var discountAmount = 0;
  3126. var nonexciseAmount = totalline_Amount - Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount);
  3127. discountAmount = (Number(nonexciseAmount) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountPercent) / 100)
  3128. + (Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountValue));
  3129. discountAmount = Number(discountAmount);
  3130. totalLineAmount_total += Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
  3131. itemdiscount_total += discountAmount;
  3132. totalDiscountAmount += discountAmount;
  3133. }
  3134. }
  3135. var overalldiscountpercent = 0;
  3136. if (adddiscountrow_total != 0) {
  3137. overalldiscountpercent = (100 * Number(adddiscountrow_total)) / Number(totalLineAmount_total);
  3138. overalldiscountpercent = Number(overalldiscountpercent);
  3139. $("#hfOverallDiscountPercent").val(overalldiscountpercent);
  3140. }
  3141. var taxAmounts = [];
  3142. $('.hfRowTotal').each(function (i) {
  3143. var element = $(this).parents(".item-row");
  3144. if (!element.hasClass('SplitItem')) {
  3145. var totalLineAmount = Number($(this).val());
  3146. var quantity = element.find(".prodQuantity").val();
  3147. var UnitPrice = element.find(".prodPrice").val();
  3148. var Discount = element.find("#inv_txtdiscount").val();
  3149. var DiscountType = element.find(".btn_inv_DiscType").val();
  3150. discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
  3151. var assesableAmount = totalLineAmount - discountAmount;
  3152. assesableAmount = Number(assesableAmount);
  3153. if (element.find(".hf_IsMultipleUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
  3154. let ItemId = Number(element.find(".selectedItemId").val());
  3155. let SelectedUnitId = Number(element.find(".hf_AlternateUnitId").val());
  3156. if (SelectedUnitId == 0 || SelectedUnitId == 1) {
  3157. SelectedUnitId = Number(element.find(".ddl_MultipleUOMs").val());
  3158. }
  3159. if (SelectedUnitId != 0 && SelectedUnitId != 1) {
  3160. let Uom = InvoiceItem.Instance().UOMs.find(x => x.ItemId == ItemId);
  3161. let SelectedUOM = Uom.MultipleUOMs.find(x => x.SchemaDetailId == SelectedUnitId);
  3162. let DefaultSize = SelectedUOM.DefaultSize;
  3163. let AlternateSize = SelectedUOM.AlternateSize;
  3164. quantity = Number(element.find(".prodQuantity").val()) * (AlternateSize / DefaultSize);
  3165. totalLineAmount = Number(assesableAmount) * (AlternateSize / DefaultSize);
  3166. element.find(".prodTotalPrice").text(totalLineAmount);
  3167. element.find(".hfRowTotalwithAdjustment").val(totalLineAmount);
  3168. let Conversion = SelectedUOM.DefaultSize + " " + SelectedUOM.DefaultUnitName + " = " + SelectedUOM.AlternateSize + " " + SelectedUOM.AlternateUnitName;
  3169. element.find(".ItemConversion").text(Conversion);
  3170. element.find(".SelectedUOMName").text('(' + SelectedUOM.DefaultUnitName + ')');
  3171. let UOMCalc = UnitPrice + ' X ' + quantity + ' ( ' + SelectedUOM.AlternateUnitName + ' )';
  3172. if (Discount > 0) {
  3173. if (DiscountType == 'Val') {
  3174. UOMCalc = '(' + UnitPrice + ' - ' + Discount + ')' + ' X ' + quantity + ' ( ' + SelectedUOM.DefaultUnitName + ' )';
  3175. }
  3176. else if (DiscountType == '%') {
  3177. UOMCalc = '(' + UnitPrice + ' - ' + Discount + '%)' + ' X ' + quantity + ' ( ' + SelectedUOM.DefaultUnitName + ' )';
  3178. }
  3179. }
  3180. element.find(".UOMCalc").text(UOMCalc);
  3181. }
  3182. else {
  3183. element.find(".ItemConversion").text("");
  3184. element.find(".UOMCalc").text("");
  3185. element.find(".SelectedUOMName").text("");
  3186. }
  3187. }
  3188. if (element.find(".hf_IsManualUOM").val() == "true" && $(".hdn_invoicetypeid").val() == "1") {
  3189. let ItemId = Number(element.find(".selectedItemId").val());
  3190. let SelectedUnitId = Number(element.find(".hf_AlternateUnitId").val());
  3191. let ConversionQuantity = Number(element.find(".hf_ConversionQuantity").val());
  3192. let AlternateUnitName = element.find(".hf_AlternateUnitName").val();
  3193. let ItemUnitName = element.find(".hf_UnitName").val();
  3194. totalLineAmount = Number(ConversionQuantity) * Number(UnitPrice);
  3195. discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
  3196. var assesableAmount = totalLineAmount - discountAmount;
  3197. assesableAmount = Number(assesableAmount);
  3198. totalLineAmount = assesableAmount;
  3199. if (SelectedUnitId != 0 && SelectedUnitId != 1) {
  3200. element.find(".prodTotalPrice").text(totalLineAmount);
  3201. element.find(".hfRowTotalwithAdjustment").val(totalLineAmount);
  3202. element.find(".SelectedUOMName").text('(' + ItemUnitName + ')');
  3203. let UOMCalc = UnitPrice + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
  3204. if (Discount > 0) {
  3205. if (DiscountType == 'Val') {
  3206. UOMCalc = '(' + UnitPrice + ' - ' + Discount + ')' + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
  3207. }
  3208. else if (DiscountType == '%') {
  3209. UOMCalc = '(' + UnitPrice + ' - ' + Discount + '%)' + ' X ' + ConversionQuantity + ' ( ' + AlternateUnitName + ' )';
  3210. }
  3211. }
  3212. element.find(".UOMCalc").text(UOMCalc);
  3213. }
  3214. else {
  3215. element.find(".ItemConversion").text("");
  3216. element.find(".UOMCalc").text("");
  3217. element.find(".SelectedUOMName").text("");
  3218. }
  3219. }
  3220. if (!isNaN(totalLineAmount))
  3221. totalNonDiscountedAmount += Number(totalLineAmount);
  3222. discountAmount = Number(element.find(".hfDiscountedAmount").val()) + (Number(totalLineAmount) * Number(overalldiscountpercent) / 100);
  3223. var assesableAmount = totalLineAmount - discountAmount;
  3224. var taxPercents = element.find(".hfProdTaxPercent").val();
  3225. if (taxPercents != undefined)
  3226. var taxpercentarray = taxPercents.toString().split(',');
  3227. var taxValue = 0;
  3228. var assesableAdjustment = Number(element.find('.hfItemAssesableAdjustmentVal').val());
  3229. var taxAdjustment = Number(element.find('.hfItemTaxAdjsutmentVal').val());
  3230. if (!isNaN(taxAdjustment))
  3231. totalTaxAdjustment += Number(taxAdjustment);
  3232. if (!isNaN(assesableAdjustment))
  3233. totalAsseableAdjustment += Number(assesableAdjustment);
  3234. var cumlTax = 0;
  3235. var cumtaxtotal = 0;
  3236. if ($(".dropdown_istaxinclusive").val() == "true") {
  3237. for (var i = 0; i < taxpercentarray.length; i++) {
  3238. var taxPercentModel1 = taxpercentarray[i];
  3239. var taxPercentM1 = taxPercentModel1.split(":");
  3240. if (!isNaN(Number(taxPercentM1[1])))
  3241. cumlTax += Number(taxPercentM1[1]);
  3242. }
  3243. var currentAmt = Number((Number(assesableAmount) * 100) / (100 + Number(cumlTax)));
  3244. cumtaxtotal = (Number(assesableAmount) - Number(currentAmt));
  3245. }
  3246. if (taxpercentarray != undefined) {
  3247. for (var i = 0; i < taxpercentarray.length; i++) {
  3248. var taxPercentModel = taxpercentarray[i];
  3249. var taxPercentM = taxPercentModel.split(":");
  3250. var ledgerid = taxPercentM[0];
  3251. var taxPercent = Number(taxPercentM[1]);
  3252. let taxAmt = 0;
  3253. if ($(".dropdown_istaxinclusive").val() == "true") {
  3254. taxAmt = Number((taxPercent * cumtaxtotal) / cumlTax);
  3255. }
  3256. else {
  3257. var tax = (Number(assesableAmount) * Number(taxPercent) / 100);
  3258. taxAmt = Number(tax);
  3259. }
  3260. var ledgerexists = false;
  3261. $.map(taxAmounts, function (e, i) {
  3262. if (e.LedgerId == ledgerid) {
  3263. ledgerexists = true;
  3264. taxAmounts[i].TaxAmount = Number(taxAmounts[i].TaxAmount) + Number(taxAmt);
  3265. }
  3266. });
  3267. if (!ledgerexists) {
  3268. taxAmounts.push({
  3269. LedgerId: ledgerid,
  3270. TaxAmount: taxAmt,
  3271. });
  3272. }
  3273. }
  3274. }
  3275. totalAmount += Number(totalLineAmount);
  3276. totalQty += Number(quantity);
  3277. }
  3278. });
  3279. if (InvoiceItem.Instance().SplitedInvoiceItemList.length > 0) {
  3280. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  3281. var TotalLineAmount = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice);
  3282. var quantiy = Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity);
  3283. if (!isNaN(TotalLineAmount))
  3284. totalNonDiscountedAmount += Number(TotalLineAmount);
  3285. var discountAmount = (quantiy * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountValue)) + ((Number(TotalLineAmount) * Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].addlDiscountPercent)) / 100) + (Number(TotalLineAmount) * Number(overalldiscountpercent) / 100);
  3286. ;
  3287. var assesableAmount = TotalLineAmount - discountAmount;
  3288. assesableAmount = Number(assesableAmount);
  3289. var taxPercents = '';
  3290. var instance = this;
  3291. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent == undefined || InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent == 0) {
  3292. var element = "";
  3293. $(".SplitItem").each(function () {
  3294. if ($(this).find(".selectedItemId").val() == InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId) {
  3295. element = $(this);
  3296. taxPercents = element.find('.hfProdTaxPercent').val();
  3297. }
  3298. });
  3299. }
  3300. else
  3301. taxPercents = InvoiceItem.Instance().SplitedInvoiceItemList[i].TaxPercent;
  3302. if (taxPercents != undefined && taxPercents != '')
  3303. var taxpercentarray = taxPercents.split(',');
  3304. var assesableAdjustment = InvoiceItem.Instance().SplitedInvoiceItemList[i].assesableAdjustment;
  3305. var taxAdjustment = InvoiceItem.Instance().SplitedInvoiceItemList[i].taxAdjustment;
  3306. if (!isNaN(taxAdjustment))
  3307. totalTaxAdjustment += Number(taxAdjustment);
  3308. if (!isNaN(assesableAdjustment))
  3309. totalAsseableAdjustment += Number(assesableAdjustment);
  3310. var cumlTax = 0;
  3311. var cumtaxtotal = 0;
  3312. if ($(".dropdown_istaxinclusive").val() == "true") {
  3313. for (var j = 0; j < taxpercentarray.length; j++) {
  3314. var taxPercentModel1 = taxpercentarray[j];
  3315. var taxPercentM1 = taxPercentModel1.split(":");
  3316. if (!isNaN(taxPercentM1[1]))
  3317. cumlTax += Number(taxPercentM1[1]);
  3318. }
  3319. var currentAmt = Number((Number(assesableAmount) * 100) / (100 + Number(cumlTax)));
  3320. cumtaxtotal = (Number(assesableAmount) - Number(currentAmt));
  3321. }
  3322. if (taxpercentarray != undefined) {
  3323. for (var k = 0; k < taxpercentarray.length; k++) {
  3324. if (taxpercentarray[k] != '' && taxpercentarray[k] != null) {
  3325. var taxPercentModel = taxpercentarray[k];
  3326. var taxPercentM = taxPercentModel.split(":");
  3327. var ledgerid = taxPercentM[0];
  3328. var taxPercent = taxPercentM[1];
  3329. var taxAmt = 0;
  3330. if ($(".dropdown_istaxinclusive").val() == "true") {
  3331. taxAmt = Number((taxPercent * cumtaxtotal) / cumlTax);
  3332. }
  3333. else {
  3334. var tax = (Number(assesableAmount) * Number(taxPercent) / 100);
  3335. taxAmt = Number(tax);
  3336. }
  3337. var ledgerexists = false;
  3338. $.map(taxAmounts, function (e, m) {
  3339. if (e.LedgerId == ledgerid) {
  3340. ledgerexists = true;
  3341. taxAmounts[m].TaxAmount = Number(taxAmounts[m].TaxAmount) + Number(taxAmt);
  3342. }
  3343. });
  3344. if (!ledgerexists) {
  3345. taxAmounts.push({
  3346. LedgerId: ledgerid,
  3347. TaxAmount: taxAmt,
  3348. });
  3349. }
  3350. }
  3351. }
  3352. }
  3353. totalAmount += Number(TotalLineAmount);
  3354. totalQty += Number(quantiy);
  3355. }
  3356. }
  3357. var taxAmount = 0;
  3358. var taxAdjustment = 0;
  3359. for (var i = 0; i < taxAmounts.length; i++) {
  3360. if (!isNaN(taxAmounts[i].TaxAmount)) {
  3361. var taxamt = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(taxAmounts[i].TaxAmount, 2);
  3362. taxAmount += Number(taxamt);
  3363. }
  3364. }
  3365. if (!isNaN(totalTaxAdjustment))
  3366. totalTaxAdjustment = totalTaxAdjustment;
  3367. if (!isNaN(totalAsseableAdjustment)) {
  3368. totalAsseableAdjustment = totalAsseableAdjustment;
  3369. }
  3370. else {
  3371. totalAsseableAdjustment = 0;
  3372. }
  3373. if (!isNaN(totalAsseableAdjustment))
  3374. totalAmount += Number(totalAsseableAdjustment);
  3375. totalTaxAmount = Number(taxAmount) + Number(totalTaxAdjustment);
  3376. totalDiscountAmount += adddiscountrow_total;
  3377. var totaltax = totalTaxAmount;
  3378. var grosstotal = totalAmount;
  3379. var creditnotes = 0;
  3380. var assessableadjustment = 0;
  3381. if (!isNaN(Number($("#txt_assessableadjustment").val())))
  3382. assessableadjustment = Number($("#txt_assessableadjustment").val());
  3383. var subtotal = grosstotal - totalDiscountAmount + assessableadjustment;
  3384. let itemCount = $("#" + Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId()).find(".InvoiceItems .item-addedrow .selectedItemId[value!='0']").length;
  3385. $("#" + Unibase.Platform.Helpers.NavigationHelper.Instance().getLastContainerId()).find("#Item_Count").text(itemCount);
  3386. var overalldiscount = 0;
  3387. var taxadjustment = 0;
  3388. if (!isNaN(Number($('#txt_taxadjustment').val()))) {
  3389. taxadjustment = Number($('#txt_taxadjustment').val());
  3390. }
  3391. totaltax = Number(totaltax) + Number(taxadjustment);
  3392. totaltax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaltax, 2);
  3393. $('#totalTax').html(totaltax);
  3394. $('.hdn_taxamount').val(totaltax);
  3395. $('#grosstotal').html(grosstotal);
  3396. $('#totalItemDiscount').html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(itemdiscount_total, 2));
  3397. $('#totalDiscount').html(totalDiscountAmount);
  3398. $("#totalinvoiceqty").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalQty, 2));
  3399. var expense = 0;
  3400. if (!isNaN(Number($('#txtOverallExpenseAmount').val()))) {
  3401. expense = Number($('#txtOverallExpenseAmount').val());
  3402. $("#totalexpense").text(expense);
  3403. }
  3404. var adjustment = 0;
  3405. var nettotal = Number(subtotal) + Number(addexpenserow_total) - Number(overalldiscount) - Number(netadddiscountrow_total) + Number(adjustment);
  3406. if ($(".dropdown_istaxinclusive").val() == "false")
  3407. nettotal += Number(totaltax);
  3408. if ($(".dropdown_istaxinclusive").val() == "true") {
  3409. subtotal = Number(subtotal) - Number(totalTaxAmount);
  3410. }
  3411. subtotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(subtotal, 2);
  3412. $('#subtotal').html(subtotal);
  3413. $('.hdn_assessableamount').val(subtotal);
  3414. $('.hdn_assessableamount').val($('#subtotal').text());
  3415. if ($("#hf_AdjustmentAccountId").val() != undefined) {
  3416. $(".hdn_adjustmentaccountId").val($("#hf_AdjustmentAccountId").val());
  3417. }
  3418. if ($("#chk_tcsapplied").val() != undefined) {
  3419. if ($("#chk_tcsapplied").prop("checked")) {
  3420. let tcstax = 0;
  3421. let tcsrate = 0;
  3422. tcsrate = InvoiceItem.Instance().TaxRate;
  3423. if (tcsrate != 0) {
  3424. tcstax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(subtotal) + Number(totalTaxAmount)) * (tcsrate / 100), 2);
  3425. $('.number_tcsamount').val(tcstax);
  3426. nettotal += Number(tcstax);
  3427. $('#lbltcsrate').text("TCS " + tcsrate + " %");
  3428. var tcsadjustment = 0;
  3429. if (!isNaN(Number($('.txt_tcsadjustment').val()))) {
  3430. tcsadjustment = Number($('.txt_tcsadjustment').val());
  3431. }
  3432. $(".number_tcstaxrate").val(tcsrate);
  3433. $('.number_tcsamount').val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(tcstax) + tcsadjustment), 2));
  3434. nettotal += tcsadjustment;
  3435. }
  3436. }
  3437. else {
  3438. $('.txt_tcsadjustment').val(0);
  3439. $('.number_tcsamount').val(0);
  3440. }
  3441. }
  3442. if ($("#chk_tdsapplied").val() != undefined) {
  3443. if ($("#chk_tdsapplied").prop("checked")) {
  3444. let taxcodeid = $(".txtAutoComplete_tdstaxcodeid").val();
  3445. let tdsrate = $(".number_tdstaxrate").val();
  3446. let tdstax = 0;
  3447. if (tdsrate != 0) {
  3448. tdstax = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(subtotal) * (Number(tdsrate) / 100), 2);
  3449. $('.number_tdsamount').val(tdstax);
  3450. }
  3451. nettotal -= Number(tdstax);
  3452. }
  3453. else {
  3454. $('.txt_tdsadjustment').val(0);
  3455. $('.number_tdsamount').val(0);
  3456. }
  3457. }
  3458. $('.nettotal').html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(nettotal, 2));
  3459. }
  3460. loadItemAutoComplete(element) {
  3461. let userinfo = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
  3462. let sessionid = userinfo.sessionId;
  3463. let postData = null;
  3464. element.find(".prodName").select2({
  3465. placeholder: "Select",
  3466. tags: false,
  3467. allowClear: true,
  3468. theme: "default select2ErrorClass",
  3469. data: [],
  3470. ajax: {
  3471. url: function (request) {
  3472. let reqUrl = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/getitemsdcitemsandinvoiceitems';
  3473. return reqUrl;
  3474. },
  3475. type: "POST",
  3476. contentType: 'application/json',
  3477. dataType: 'json',
  3478. data: function (params) {
  3479. let Term = params.term;
  3480. sessionid = sessionid.replace('#', '');
  3481. postData = {
  3482. LobId: Number($(".hfAutoCompleteId_lobid").val()),
  3483. ItemIds: InvoiceItem.instance.itemIds,
  3484. term: Term,
  3485. };
  3486. return JSON.stringify(postData);
  3487. },
  3488. beforeSend: function (xhr) {
  3489. if (userinfo !== undefined && userinfo !== null) {
  3490. xhr.setRequestHeader("Authorization", "Basic " + userinfo.sessionId);
  3491. xhr.setRequestHeader('geoposition', userinfo.latd + ':' + userinfo.lgId);
  3492. }
  3493. },
  3494. processResults: function (data) {
  3495. return {
  3496. results: jQuery.map(JSON.parse(data.result), function (item) {
  3497. return {
  3498. id: item.Value,
  3499. text: item.SelectText,
  3500. addlInfo: item.addlData
  3501. };
  3502. })
  3503. };
  3504. },
  3505. },
  3506. });
  3507. }
  3508. itemChange(element, id, hdnAutoId) {
  3509. id = element.find(".prodName option:selected").val();
  3510. element.find(".prodName").change(function () {
  3511. if (id == null || id == 0) {
  3512. id = element.find(".prodName option:selected").val();
  3513. }
  3514. id = element.find(".prodName option:selected").val();
  3515. if (id != 0) {
  3516. var hdnItemId = id;
  3517. element.find(".selectedItemId").val(id);
  3518. if (id.search(':') == -1)
  3519. hdnItemId = id;
  3520. else
  3521. hdnItemId = id.split(':')[1];
  3522. if (element.find(".hfoldItemId").val() != hdnItemId) {
  3523. if (element.find(".orderItemId").val() == "0" && hdnItemId != "") {
  3524. if (element.find(".hfoldItemId").val() != "0" && element.find(".hfoldItemId").val() != undefined && element.find(".hfoldItemId").val() != "") {
  3525. let index = InvoiceItem.Instance().itemIds.indexOf(Number(element.find(".hfoldItemId").val()), 0);
  3526. if (index > -1) {
  3527. InvoiceItem.Instance().itemIds.splice(index, 1);
  3528. }
  3529. }
  3530. InvoiceItem.Instance().itemIds.push(Number(hdnItemId));
  3531. }
  3532. var x = [];
  3533. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  3534. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == element.find(".hfoldItemId").val()) {
  3535. x.push(i);
  3536. }
  3537. }
  3538. for (var i = x.length - 1; i >= 0; i--) {
  3539. InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
  3540. }
  3541. $('.item-row').each(function () {
  3542. if ($(this).find('.hfOfferedItemId').val() == element.find(".hfoldItemId").val())
  3543. $(this).remove();
  3544. });
  3545. element.find(".hfoldItemId").val(hdnItemId);
  3546. element.find(".div_UnitPrice").removeClass('hidden');
  3547. element.find(".div_SplitInvoiceItem").addClass("hidden");
  3548. element.find(".prodQuantity").val(0);
  3549. element.find(".prodPrice").val(0);
  3550. element.find(".prodQuantity").prop('disabled', false);
  3551. element.find('.prodQuantity').css('cursor', 'default');
  3552. element.find('.prodPrice').css('cursor', 'default');
  3553. element.find("#inv_txtdiscount").css('cursor', 'default');
  3554. element.find('#inv_txtdiscount').prop('disabled', false);
  3555. element.find('#inv_txtdiscount').val(0);
  3556. element.find('.btn_inv_DiscType').removeClass('hidden');
  3557. element.find(".btn_inv_DiscType").prop('disabled', false);
  3558. element.find(".prodTax").empty();
  3559. element.find(".txt_Account").empty();
  3560. if (element.hasClass('SplitItem')) {
  3561. element.find(".spn_InvoiceItem").unbind("click", null);
  3562. }
  3563. element.find(".hfRowTotalwithAdjustment").val("0");
  3564. element.find('.prodTotalPrice').text('0');
  3565. $("#txt_Adjustment").val("0");
  3566. InvoiceItem.Instance().update_total();
  3567. InvoiceItem.Instance().TotalAdjustment();
  3568. element.removeClass('SplitItem');
  3569. element.find(".hfMrpId").val(0);
  3570. }
  3571. if ($(hdnAutoId).val().toString().search(':') == -1)
  3572. element.find(".hfoldItemId").val($(hdnAutoId).val());
  3573. else
  3574. element.find(".hfoldItemId").val($(hdnAutoId).val().toString().split(':')[1]);
  3575. var hdnSelectedItemIdVal = 0;
  3576. hdnSelectedItemIdVal = id;
  3577. if (id != 0) {
  3578. id = id;
  3579. var hdnOrderItemIdVal = 0;
  3580. var hdnDcItemIdVal = 0;
  3581. var ids = $(hdnAutoId).val();
  3582. if (ids.toString().search(':') == -1) {
  3583. hdnSelectedItemIdVal = Number($(hdnAutoId).val());
  3584. }
  3585. else {
  3586. var selectedVal = hdnAutoId;
  3587. if (!InvoiceItem.Instance().AutoDc) {
  3588. hdnOrderItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
  3589. if (InvoiceItem.Instance().orderid != 0 && InvoiceItem.Instance().OrderSettingId == 2)
  3590. hdnOrderItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
  3591. else {
  3592. hdnDcItemIdVal = Number($(selectedVal).val().toString().split(':')[0]);
  3593. element.find(".dcItemId").val(hdnDcItemIdVal);
  3594. let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(hdnDcItemIdVal, 0);
  3595. if (dcindex == -1)
  3596. InvoiceItem.Instance().dcItemIds.push(hdnDcItemIdVal);
  3597. }
  3598. }
  3599. hdnSelectedItemIdVal = Number($(selectedVal).val().toString().split(':')[1]);
  3600. }
  3601. var item = element.find(".prodName").text();
  3602. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemById(hdnSelectedItemIdVal).then(function (response) {
  3603. var inventarytype = response.result.InventoryTypeId;
  3604. if (inventarytype == 5 || inventarytype == 6) {
  3605. InvoiceItem.Instance().addDiscountRow(element, item, id);
  3606. var elementfordisc = $(".discount-row:last");
  3607. InvoiceItem.Instance().loadItemRowDetails(elementfordisc, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
  3608. }
  3609. else if (inventarytype == 7) {
  3610. InvoiceItem.Instance().addExpenseRow(element, item, id, true);
  3611. var elementforexp = $(".expense-row:last");
  3612. InvoiceItem.Instance().loadItemRowDetails(elementforexp, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
  3613. }
  3614. else {
  3615. var itemid = 0;
  3616. if (hdnSelectedItemIdVal == undefined) {
  3617. InvoiceItem.Instance().loadItemRowDetails(element, 0, hdnDcItemIdVal, hdnSelectedItemIdVal);
  3618. }
  3619. else {
  3620. InvoiceItem.Instance().loadItemRowDetails(element, hdnOrderItemIdVal, hdnDcItemIdVal, hdnSelectedItemIdVal);
  3621. }
  3622. }
  3623. });
  3624. }
  3625. }
  3626. });
  3627. }
  3628. itemsAutoComplete(element) {
  3629. var txtAutoSearchCtrl = element.find(".prodName");
  3630. var hdnOrderItemId = element.find(".orderItemId");
  3631. var hdnDcItemId = element.find(".dcItemId");
  3632. var hdnSelectedItemId = element.find(".selectedItemId");
  3633. let lobid = $(".hfAutoCompleteId_lobid").val();
  3634. if ((hdnSelectedItemId).val() != 0 && (hdnSelectedItemId).val() != "") {
  3635. this.itemIds.push(Number((hdnSelectedItemId).val()));
  3636. element.find(".hfoldItemId").val((hdnSelectedItemId).val());
  3637. }
  3638. let hdnAutoId = hdnSelectedItemId;
  3639. let orderid = InvoiceItem.Instance().orderid;
  3640. let dcid = InvoiceItem.Instance().dcid;
  3641. let invoiceid = $(".hdn_invoiceid").val();
  3642. if (invoiceid == undefined || invoiceid == "null")
  3643. invoiceid = 0;
  3644. var url = "";
  3645. var id = 0;
  3646. if ((orderid == 0) && (InvoiceItem.Instance().AutoDc) && InvoiceItem.Instance().OrderSettingId == 0 && ($('#hfInv_IsRetun').val() != "1" && ($(".hdn_refinvoiceid").val() == undefined || $(".hdn_refinvoiceid").val() == 0))) {
  3647. InvoiceItem.instance.loadItemAutoComplete(element);
  3648. }
  3649. else {
  3650. if ((orderid == 0) && (dcid != 0 && InvoiceItem.Instance().AutoDc == false))
  3651. url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autodcitemforinvoicewithoutorder/dcid/" + dcid + "/itemids/" + InvoiceItem.Instance().itemIds;
  3652. else if (InvoiceItem.Instance().OrderSettingId == 1)
  3653. url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autodcitemforinvoice/dcid/" + dcid + "/itemids/" + InvoiceItem.Instance().dcItemIds;
  3654. else
  3655. url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autopendingorderitemforinvoice/orderid/" + orderid + "/itemids/" + InvoiceItem.Instance().itemIds;
  3656. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && ($('#hfInv_IsRetun').val() == "1" || ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0))) {
  3657. var refinvoiceid = 0;
  3658. if ($('#hfInv_IsRetun').val() == "1") {
  3659. refinvoiceid = Number(invoiceid);
  3660. $(".hdn_refinvoiceid").val(refinvoiceid);
  3661. }
  3662. if ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0)
  3663. refinvoiceid = Number($(".hdn_refinvoiceid").val());
  3664. url = _appsettings.server_url() + "/apis/v4/bizgaze/transact/invoices/autopendingreturnitemforinvoice/invoiceid/" + refinvoiceid + "/itemids/" + InvoiceItem.Instance().itemIds;
  3665. }
  3666. AutoCompleteHelper.getHelper().Create(txtAutoSearchCtrl, hdnAutoId, url, function (result) {
  3667. InvoiceItem.instance.itemChange(element, result.id, hdnAutoId);
  3668. });
  3669. }
  3670. InvoiceItem.Instance().loadItemRowDetails(element, hdnOrderItemId.val(), hdnDcItemId.val(), $(hdnSelectedItemId).val());
  3671. }
  3672. addDiscountRow(element, txtAutoSearchCtrl, hdnAutoId) {
  3673. InvoiceItem.Instance().RemoveItem(element);
  3674. InvoiceItem.Instance().adddiscountrow(null, txtAutoSearchCtrl, hdnAutoId, false);
  3675. }
  3676. adddiscountrow(row, txtAutoSearchCtrl, hdnAutoId, applyOnNet) {
  3677. let isemptyrow = false;
  3678. $(".addednetdiscount-row").each(function () {
  3679. if ($(this).find(".txtDiscountName").val() == undefined || $(this).find(".txtDiscountName").val() == null) {
  3680. isemptyrow = true;
  3681. }
  3682. });
  3683. if (isemptyrow) {
  3684. MessageHelper.Instance().showError("Please Select Coupon Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  3685. return false;
  3686. }
  3687. var discountid = 0;
  3688. var discountname = '';
  3689. var description = '';
  3690. var ledgerId = 0;
  3691. var rowname = "discount-row";
  3692. var percent = 0.0;
  3693. var value = 0.0;
  3694. var invoicechargeid = 0;
  3695. var appliedWhole = false;
  3696. var inventorytypeid = 6;
  3697. var readonly = "";
  3698. if (applyOnNet) {
  3699. rowname = "netdiscount-row";
  3700. appliedWhole = true;
  3701. inventorytypeid = 5;
  3702. }
  3703. if ($("#hfDirectInvoice").val() == "0")
  3704. invoicechargeid = 0;
  3705. var html = '<div class="' + rowname + ' added' + rowname + ' row mb-2 mx-0" ' + readonly + '>' +
  3706. '<div class="discount-name col-sm-4">' +
  3707. '<div class="floating-label-form-group min-padding" style="margin-left:20px;border-bottom:0px"><input type="hidden" class="selectedInvoiceChargeId" value="' + invoicechargeid + '" />';
  3708. if (row != null) {
  3709. if (row.addlDiscountPercent != "") {
  3710. percent = row.addlDiscountPercent;
  3711. }
  3712. if (row.addlDiscountValue != "") {
  3713. value = row.addlDiscountValue;
  3714. }
  3715. if (row.description != "" && row.description != null) {
  3716. description = row.description;
  3717. }
  3718. html += '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  3719. '<input type="hidden" class="orderItemId" value="' + row.orderItemId + '" />' +
  3720. '<input type="hidden" class="dcItemId" value="' + row.dcItemId + '" />' +
  3721. '<input type="hidden" class="selectedInvoiceItemId" value="' + row.invoiceItemId + '" />' +
  3722. '<input type="hidden" class="refInvoiceItemId" value="' + row.RefInvoiceItemId + '" />' +
  3723. '<input type="hidden" class="selectedItemId" value="' + row.itemId + '" />' +
  3724. '<input type="hidden" class="inventorytypeid" value="' + row.itemId + '" />' +
  3725. '<input type="hidden" class="selectedItemName" value="' + row.itemname + '" />' +
  3726. '<input type="hidden" class="hfMrpId" value="' + row.MrpId + '" />' +
  3727. '<input type="hidden" class="offerapplied" value="0" />' +
  3728. '<input type="hidden" class="refNo" value="' + row.refNo + '" />' +
  3729. '<input type="hidden" class="description" value="' + row.description + '" />' +
  3730. '<input type="hidden" class="IsExchangeItem" value="' + row.ExchangeItem + '" />' +
  3731. '<input type="hidden" class="maxQty" value="' + row.maxQty + '" />' +
  3732. '<input type="hidden" class="hf_Account" value="' + row.accountId + '" />' +
  3733. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="' + row.taxAdjustment + '" />' +
  3734. '<input type="hidden" class="hfProdTax" value="' + row.taxGroupId + '" />' +
  3735. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="' + row.assesableAdjustment + '" />' +
  3736. '<input type="hidden" class="prodPrice text-center form-control" placeholder="0.00" value="0" />';
  3737. }
  3738. else {
  3739. html += '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  3740. '<input type="hidden" class="orderItemId" value="0" />' +
  3741. '<input type="hidden" class="dcItemId" value="0" />' +
  3742. '<input type="hidden" class="selectedInvoiceItemId" value="0" />' +
  3743. '<input type="hidden" class="selectedItemName" value="" />' +
  3744. '<input type="hidden" class="refInvoiceItemId" value="0" />' +
  3745. '<input type="hidden" class="selectedItemId" value="0" />' +
  3746. '<input type="hidden" class="inventorytypeid" value="0" />' +
  3747. '<input type="hidden" class="hfMrpId" value="0" />' +
  3748. '<input type="hidden" class="offerapplied" value="0" />' +
  3749. '<input type="hidden" class="refNo" value="0" />' +
  3750. '<input type="hidden" class="description" value="0" />' +
  3751. '<input type="hidden" class="IsExchangeItem" value="0" />' +
  3752. '<input type="hidden" class="maxQty" value="0" />' +
  3753. '<input type="hidden" class="hf_Account" value="0" />' +
  3754. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="0" />' +
  3755. '<input type="hidden" class="hfProdTax" value="0" />' +
  3756. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="0" />' +
  3757. '<input type="hidden" class="prodPrice text-center form-control" placeholder="0.00" value="0" />';
  3758. }
  3759. html += '<div class="input-group">' +
  3760. '<input type="hidden" class="hdnChargeTypeId" value="2" />' +
  3761. '<input type="hidden" class="hdnChargeLedgerId" value="' + ledgerId + '" />' +
  3762. '<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>';
  3763. if (rowname == "netdiscount-row") {
  3764. html += '<select type="text" class="txtDiscountName ui-autocomplete form-control text-control readonly' + readonly + '" placeholder=" Discount name" value="' + discountname + '" style="width:100%;"></select>';
  3765. }
  3766. else {
  3767. html += '<select type="text" class="txtDiscountName ui-autocomplete form-control readonly" placeholder=" Discount name" value="' + discountname + '" style="width:100%;"></select>';
  3768. }
  3769. html += '<input type="hidden" class="hfSelectedChargeId" value="' + discountid + '" />' +
  3770. '</div>' +
  3771. '</div></div>' +
  3772. '<div class="col-sm-4">' +
  3773. '<div class="floating-label-form-group min-padding"><input type="text" class="discountDesc form-control" placeholder="Description" value="' + description + '" /></div></div>' +
  3774. '<div class="col-sm-1">' +
  3775. '<div class="floating-label-form-group min-padding"><input type="text" class="percentage text-center form-control" placeholder="%" value="' + percent + '" /></div></div>' +
  3776. '<div class="col-sm-1">' +
  3777. '<div class="floating-label-form-group min-padding"><input type="text" class="fixedvalue text-center form-control" placeholder="0.00" value="' + value + '" /></div></div>' +
  3778. '<div class="col-sm-2 mt-10"><p class="pull-right"><span class="' + rowname + '-total control-label mt-5">0</span></p></div>' +
  3779. '</div>';
  3780. $("." + rowname + ":last").after(html);
  3781. var element = $("." + rowname + ":last");
  3782. InvoiceItem.Instance().bind(element, inventorytypeid);
  3783. if (inventorytypeid == 5)
  3784. InvoiceItem.Instance().GetOnInvoiceDiscountItem(element);
  3785. var txtChargeCode = element.find(".txtDiscountName");
  3786. var hfSelectedChargeId = element.find(".hfSelectedChargeId");
  3787. $(hfSelectedChargeId).val(hdnAutoId);
  3788. if (hdnAutoId != 0) {
  3789. var selecteditem = new Option(txtAutoSearchCtrl, hdnAutoId, true);
  3790. txtChargeCode.append(selecteditem);
  3791. }
  3792. if (rowname == "netdiscount-row" || rowname == "discount-row") {
  3793. var id = 0;
  3794. if (row != null) {
  3795. var selecteditem = new Option(row.itemName, row.itemId, true);
  3796. txtChargeCode.append(selecteditem);
  3797. }
  3798. let typeid = "7";
  3799. if (rowname == "discount-row") {
  3800. typeid = "5,6";
  3801. }
  3802. var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/itemautocompletebyinventorytype/inventorytypeid/' + Number(inventorytypeid) + '/lobid/' + $(".hfAutoCompleteId_lobid").val() + '/invoicetypeid/' + $('.hdn_invoicetypeid').val();
  3803. AutoCompleteHelper.getHelper().Create(txtChargeCode, hfSelectedChargeId, url, function (result) {
  3804. if (id != result.id) {
  3805. id = result.id;
  3806. var elementfordisc = $(".netdiscount-row:last");
  3807. var hdnOrderItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[0];
  3808. var hdnSelectedItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[1];
  3809. if (result.addlData != undefined && result.addlData != null) {
  3810. var defaultpercent = Number(result.addlData.split(':')[0]);
  3811. var defaultvalue = Number(result.addlData.split(':')[1]);
  3812. element.find('.percentage').val(defaultpercent);
  3813. element.find('.fixedvalue').val(defaultvalue);
  3814. }
  3815. InvoiceItem.Instance().loadItemRowDetails(element, 0, 0, hdnOrderItemIdVal);
  3816. }
  3817. });
  3818. }
  3819. $('.percentage').keypress(function (event) {
  3820. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  3821. }
  3822. else {
  3823. event.preventDefault();
  3824. }
  3825. }).on('paste', function (event) {
  3826. event.preventDefault();
  3827. });
  3828. $('.fixedvalue').keypress(function (event) {
  3829. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  3830. }
  3831. else {
  3832. event.preventDefault();
  3833. }
  3834. }).on('paste', function (event) {
  3835. event.preventDefault();
  3836. });
  3837. }
  3838. addExpenseRow(row, txtAutoSearchCtrl, hdnAutoId, applyOnNet) {
  3839. let isemptyrow = false;
  3840. $(".addedexpense-row").each(function () {
  3841. if ($(this).find(".txtExpenseName").val() == undefined || $(this).find(".txtExpenseName").val() == null) {
  3842. isemptyrow = true;
  3843. }
  3844. });
  3845. if (isemptyrow) {
  3846. MessageHelper.Instance().showError("Please Select Expense Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  3847. return false;
  3848. }
  3849. var discountid = 0;
  3850. var discountname = '';
  3851. var description = '';
  3852. var ledgerId = 0;
  3853. var rowname = "expense-row";
  3854. var percent = 0.0;
  3855. var value = 0.0;
  3856. var invoicechargeid = 0;
  3857. var appliedWhole = true;
  3858. var inventorytypeid = 7;
  3859. if ($("#hfDirectInvoice").val() == "0")
  3860. invoicechargeid = 0;
  3861. var html = '<div class="' + rowname + ' added' + rowname + ' row mb-2" >' +
  3862. '<div class="expense-name col-sm-4">' +
  3863. '<div class="floating-label-form-group min-padding" style="margin-left:20px;border-bottom:0px"><input type="hidden" class="selectedInvoiceChargeId" value="' + invoicechargeid + '" />';
  3864. if (row != null) {
  3865. if (row.addlDiscountPercent != "") {
  3866. percent = -row.addlDiscountPercent;
  3867. }
  3868. if (row.addlDiscountValue != "") {
  3869. value = -row.addlDiscountValue;
  3870. }
  3871. if (row.description != "") {
  3872. description = row.description;
  3873. }
  3874. html += '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  3875. '<input type="hidden" class="orderItemId" value="' + row.orderItemId + '" />' +
  3876. '<input type="hidden" class="dcItemId" value="' + row.dcItemId + '" />' +
  3877. '<input type="hidden" class="selectedInvoiceItemId" value="' + row.invoiceItemId + '" />' +
  3878. '<input type="hidden" class="refInvoiceItemId" value="' + row.RefInvoiceItemId + '" />' +
  3879. '<input type="hidden" class="selectedItemId" value="' + row.itemId + '" />' +
  3880. '<input type="hidden" class="inventorytypeid" value="' + row.itemId + '" />' +
  3881. '<input type="hidden" class="selectedItemName" value="' + row.itemname + '" />' +
  3882. '<input type="hidden" class="hfMrpId" value="' + row.MrpId + '" />' +
  3883. '<input type="hidden" class="offerapplied" value="0" />' +
  3884. '<input type="hidden" class="refNo" value="' + row.refNo + '" />' +
  3885. '<input type="hidden" class="description" value="' + row.description + '" />' +
  3886. '<input type="hidden" class="IsExchangeItem" value="' + row.ExchangeItem + '" />' +
  3887. '<input type="hidden" class="maxQty" value="' + row.maxQty + '" />' +
  3888. '<input type="hidden" class="hf_Account" value="' + row.accountId + '" />' +
  3889. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="' + row.taxAdjustment + '" />' +
  3890. '<input type="hidden" class="hfProdTax" value="' + row.taxGroupId + '" />' +
  3891. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="' + row.assesableAdjustment + '" />' +
  3892. '<input type="hidden" class="prodPrice text-center form-control" placeholder="0.00" value="0" />';
  3893. }
  3894. else {
  3895. html += '<input type="hidden" class="rowIndex" value="' + this.rowIndex + '" />' +
  3896. '<input type="hidden" class="orderItemId" value="0" />' +
  3897. '<input type="hidden" class="dcItemId" value="0" />' +
  3898. '<input type="hidden" class="selectedInvoiceItemId" value="0" />' +
  3899. '<input type="hidden" class="selectedItemName" value="" />' +
  3900. '<input type="hidden" class="refInvoiceItemId" value="0" />' +
  3901. '<input type="hidden" class="selectedItemId" value="0" />' +
  3902. '<input type="hidden" class="inventorytypeid" value="0" />' +
  3903. '<input type="hidden" class="hfMrpId" value="0" />' +
  3904. '<input type="hidden" class="offerapplied" value="0" />' +
  3905. '<input type="hidden" class="refNo" value="0" />' +
  3906. '<input type="hidden" class="description" value="0" />' +
  3907. '<input type="hidden" class="IsExchangeItem" value="0" />' +
  3908. '<input type="hidden" class="maxQty" value="0" />' +
  3909. '<input type="hidden" class="hf_Account" value="0" />' +
  3910. '<input type="hidden" class="hfItemTaxAdjsutmentVal" value="0" />' +
  3911. '<input type="hidden" class="hfProdTax" value="0" />' +
  3912. '<input type="hidden" class="hfItemAssesableAdjustmentVal" value="0" />' +
  3913. '<input type="hidden" class="prodPrice text-center form-control" placeholder="0.00" value="0" />';
  3914. }
  3915. html += '<div class="input-group">' +
  3916. '<input type="hidden" class="hdnChargeTypeId" value="1" />' +
  3917. '<input type="hidden" class="hdnChargeLedgerId" value="' + ledgerId + '" />' +
  3918. '<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>';
  3919. html += '<select type="text" class="txtExpenseName ui-autocomplete form-control readonly" placeholder=" Expense name" value="' + discountname + '" style="width:100%;"></select>';
  3920. html += '<input type="hidden" class="hfSelectedChargeId" value="' + discountid + '" />' +
  3921. '</div>' +
  3922. '</div></div>' +
  3923. '<div class="col-sm-4">' +
  3924. '<div class="floating-label-form-group min-padding"><input type="text" class="expenseDesc form-control" placeholder="Description" value="' + description + '" /></div></div>' +
  3925. '<div class="col-sm-1">' +
  3926. '<div class="floating-label-form-group min-padding"><input type="text" class="exppercentage text-center form-control" placeholder="%" value="' + percent + '" /></div></div>' +
  3927. '<div class="col-sm-1">' +
  3928. '<div class="floating-label-form-group min-padding"><input type="text" class="expfixedvalue text-center form-control" placeholder="0.00" value="' + value + '" /></div></div>' +
  3929. '<div class="col-sm-2 mt-10"><p class="pull-right"><span class="' + rowname + '-total control-label mt-5">0</span></p></div>' +
  3930. '</div>';
  3931. $("." + rowname + ":last").after(html);
  3932. var element = $("." + rowname + ":last");
  3933. InvoiceItem.Instance().bind(element, inventorytypeid);
  3934. var txtChargeCode = element.find(".txtExpenseName");
  3935. var hfSelectedChargeId = element.find(".hfSelectedChargeId");
  3936. $(hfSelectedChargeId).val(hdnAutoId);
  3937. if (hdnAutoId != 0) {
  3938. var selecteditem = new Option(txtAutoSearchCtrl, hdnAutoId, true);
  3939. txtChargeCode.append(selecteditem);
  3940. }
  3941. if (rowname == "expense-row") {
  3942. var id = 0;
  3943. if (row != null) {
  3944. var selecteditem = new Option(row.itemName, row.itemId, true);
  3945. txtChargeCode.append(selecteditem);
  3946. }
  3947. let typeid = "7";
  3948. var url = _appsettings.server_url() + '/apis/v4/bizgaze/transact/items/itemautocompletebyinventorytype/inventorytypeid/' + Number(inventorytypeid) + '/lobid/' + $(".hfAutoCompleteId_lobid").val() + '/invoicetypeid/' + $('.hdn_invoicetypeid').val();
  3949. AutoCompleteHelper.getHelper().Create(txtChargeCode, hfSelectedChargeId, url, function (result) {
  3950. if (id != result.id) {
  3951. id = result.id;
  3952. var elementfordisc = $(".expense-row:last");
  3953. var hdnOrderItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[0];
  3954. var hdnSelectedItemIdVal = $(hfSelectedChargeId).val().toString().split(':')[1];
  3955. InvoiceItem.Instance().loadItemRowDetails(element, 0, 0, hdnOrderItemIdVal);
  3956. }
  3957. });
  3958. }
  3959. $('.exppercentage').keypress(function (event) {
  3960. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  3961. }
  3962. else {
  3963. event.preventDefault();
  3964. }
  3965. }).on('paste', function (event) {
  3966. event.preventDefault();
  3967. });
  3968. $('.expfixedvalue').keypress(function (event) {
  3969. if ((event.which > 47 && event.which < 58) || (event.which == 46 || event.which == 8)) {
  3970. }
  3971. else {
  3972. event.preventDefault();
  3973. }
  3974. }).on('paste', function (event) {
  3975. event.preventDefault();
  3976. });
  3977. }
  3978. loadItemRowDetails(element, orderItemId, dcItemId, itemId) {
  3979. var instance = this;
  3980. if (orderItemId == '' || ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4"))
  3981. orderItemId = 0;
  3982. if (dcItemId == '' || ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  3983. dcItemId = 0;
  3984. }
  3985. if ((orderItemId != 0 && orderItemId != undefined) || (itemId != 0 && itemId != undefined) || (dcItemId != 0 && dcItemId != undefined)) {
  3986. let lobId = $(".hfAutoCompleteId_lobid").val();
  3987. let billingAddressId = $('.txtAutoComplete_billtoaddressid').val();
  3988. if (billingAddressId == "0" || billingAddressId == "" || billingAddressId == null) {
  3989. MessageHelper.Instance().showError("Please select bill to address", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  3990. return false;
  3991. }
  3992. var portalId = 0;
  3993. var ShipfromAddressId = 0;
  3994. let invoiceid = $(".hdn_invoiceid").val();
  3995. if (invoiceid == undefined)
  3996. invoiceid = 0;
  3997. ShipfromAddressId = Number($(".txtAutoComplete_shipfromaddressid").val());
  3998. var ShiptoAddressId = Number($(".txtAutoComplete_shiptoaddressid").val());
  3999. portalId = Number($(".txtAutoComplete_billfromaddressid").val());
  4000. var MrpId = element.find(".hfMrpId").val();
  4001. if (MrpId == undefined)
  4002. MrpId = 0;
  4003. var isconfirm = false;
  4004. var invoicemode = "1";
  4005. var invoiceType = $('.hdn_invoicetypeid').val();
  4006. if (itemId == undefined)
  4007. itemId = 0;
  4008. var contactId = $(".hdn_organizationid").val();
  4009. if (contactId == 0)
  4010. contactId = $(".hfAutoCompleteId_orgcontactid").val();
  4011. var invoiceapplytype = 1;
  4012. if ($(".hdn_invoicetypeid").val() == "2" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "7") {
  4013. invoiceapplytype = 2;
  4014. }
  4015. let ApplyDate = moment($('.date_journaldate').val().toString(), "DD/MM/YYYY").format("YYYY-MM-DD");
  4016. var refinvoiceid = 0;
  4017. if ($(".hdn_refinvoiceid").val() != undefined && $(".hdn_refinvoiceid").val() != 0)
  4018. refinvoiceid = Number($(".hdn_refinvoiceid").val());
  4019. var post = {
  4020. OrderItemId: Number(orderItemId),
  4021. DcItemId: Number(dcItemId),
  4022. ItemId: Number(itemId),
  4023. BillingAddressId: Number(billingAddressId),
  4024. BillFromAddressId: portalId,
  4025. DefaultPriceListId: 0,
  4026. InvoiceType: Number(invoiceType),
  4027. MrpId: Number(MrpId),
  4028. InvoiceMode: Number(invoicemode),
  4029. isCform: Boolean(isconfirm),
  4030. LobId: Number(lobId),
  4031. contactId: Number(contactId),
  4032. InvoiceApplyType: invoiceapplytype,
  4033. ShipFromAddressId: ShipfromAddressId,
  4034. ShipToAddressId: ShiptoAddressId,
  4035. AutoDC: InvoiceItem.instance.AutoDc,
  4036. InvoiceDate: ApplyDate,
  4037. RefInvoiceId: refinvoiceid
  4038. };
  4039. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemDetails(post).then(function (response) {
  4040. var itemdata = response.result;
  4041. element.find(".selectedItemId").val(itemdata.ItemId);
  4042. if (itemdata.orderItemId == 0)
  4043. element.find(".orderItemId").val(orderItemId);
  4044. else
  4045. element.find(".orderItemId").val(itemdata.OrderItemId);
  4046. itemId = itemdata.ItemId;
  4047. element.find(".spnProdName").text(itemdata.ItemName);
  4048. element.find(".selectedItemName").text(itemdata.ItemName + ' - ' + itemdata.ItemSKU);
  4049. element.find("#inventorytypeid").val(itemdata.InventoryTypeId);
  4050. var prodPrice = element.find(".prodPrice");
  4051. var prodQty = element.find(".prodQuantity");
  4052. var priceListId = element.find(".hfPriceList");
  4053. var isSplitItem = false;
  4054. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  4055. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
  4056. isSplitItem = true;
  4057. }
  4058. }
  4059. if (itemdata.AccountId != 0 && (element.find(".selectedInvoiceItemId").val() == "0" || (itemdata.InventoryTypeId == 5)) && !isSplitItem) {
  4060. var selectedAccount = new Option(itemdata.AccountName, itemdata.AccountId, true);
  4061. element.find(".txt_Account").empty();
  4062. element.find(".txt_Account").append(selectedAccount);
  4063. element.find(".hf_Account").val(itemdata.AccountId);
  4064. element.find(".txt_AccountName").val(itemdata.AccountName);
  4065. }
  4066. if (itemdata.TaxGroupId != 0 && (element.find(".selectedInvoiceItemId").val() == "0" || (itemdata.InventoryTypeId == 5)) && !isSplitItem) {
  4067. var txtTaxGroup = element.find(".prodTax");
  4068. var hfTaxGroupId = element.find(".hfProdTax");
  4069. txtTaxGroup.empty();
  4070. var selectedTaxgrp = new Option(itemdata.TaxGroupName, itemdata.TaxGroupId, true);
  4071. txtTaxGroup.append(selectedTaxgrp);
  4072. element.find(".txtProdTax").val(itemdata.TaxGroupName);
  4073. hfTaxGroupId.val(itemdata.TaxGroupId);
  4074. InvoiceItem.Instance().update_tax(element, itemdata.TaxGroupId);
  4075. }
  4076. if (element.find(".selectedInvoiceItemId").val() == "0" && !isSplitItem) {
  4077. prodPrice.val(itemdata.UnitPrice);
  4078. element.find(".hf_UnitPrice").val(itemdata.UnitPrice);
  4079. priceListId.val(itemdata.PriceListId);
  4080. if (itemdata.AddlDisountValue > 0) {
  4081. element.find(".btnInvoice_DiscType option[value='Val']").prop("selected", true);
  4082. element.find('.inv_txtaddldiscount').val(itemdata.AddlDisountValue);
  4083. }
  4084. else if (itemdata.AddlDiscountPercent > 0) {
  4085. element.find(".btnInvoice_DiscType option[value='%']").prop("selected", true);
  4086. element.find('.inv_txtaddldiscount').val(itemdata.AddlDiscountPercent);
  4087. }
  4088. }
  4089. if ($(".hdn_invoiceid").val() != "0") {
  4090. element.find(".prodAvail").text(itemdata.AvailableQty);
  4091. element.find(".hfAvail").val(itemdata.AvailableQty);
  4092. }
  4093. else {
  4094. element.find(".prodAvail").text(itemdata.AvailableQty);
  4095. element.find(".hfAvail").val(itemdata.AvailableQty);
  4096. }
  4097. var dcid = InvoiceItem.Instance().dcid;
  4098. if (dcid == undefined)
  4099. dcid = 0;
  4100. 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") {
  4101. element.find(".div_UnitPrice").addClass('hidden');
  4102. element.find(".div_SplitInvoiceItem").removeClass("hidden");
  4103. element.find(".prodQuantity").prop('disabled', true);
  4104. element.find(".prodQuantity").css('cursor', "not-allowed");
  4105. element.find("#inv_txtdiscount").prop('disabled', true);
  4106. element.find("#inv_txtdiscount").css('cursor', "not-allowed");
  4107. element.find('.btn_inv_DiscType').addClass('hidden');
  4108. element.find(".btn_inv_DiscType").prop('disabled', true);
  4109. element.find(".prodTax").removeClass("required");
  4110. element.find(".txt_Account").removeClass("required");
  4111. element.addClass('SplitItem');
  4112. var ItemExist = false;
  4113. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  4114. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
  4115. ItemExist = true;
  4116. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId == 0)
  4117. InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice = itemdata.UnitPrice;
  4118. }
  4119. }
  4120. var type = '';
  4121. if (itemdata.EnableBatchNo == true) {
  4122. if (ItemExist == true)
  4123. element.find(".spn_InvoiceItem").text("View BatchNo");
  4124. else
  4125. element.find(".spn_InvoiceItem").text("Select BatchNo");
  4126. type = "BatchNo";
  4127. }
  4128. else if (itemdata.EnableMrp == true) {
  4129. if (ItemExist == true)
  4130. element.find(".spn_InvoiceItem").text("View MRP");
  4131. else
  4132. element.find(".spn_InvoiceItem").text("Select MRP");
  4133. type = "MRP";
  4134. }
  4135. else {
  4136. if (ItemExist == true)
  4137. element.find(".spn_InvoiceItem").text("View SerialNo");
  4138. else
  4139. element.find(".spn_InvoiceItem").text("Select SerialNo");
  4140. type = 'SerialNo';
  4141. }
  4142. let d = InvoiceItem.instance.AutoDc;
  4143. if (d == false && dcItemId != 0 && element.find(".selectedInvoiceItemId").val() == "0") {
  4144. var Isitemadded = false;
  4145. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  4146. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId == dcItemId) {
  4147. Isitemadded = true;
  4148. }
  4149. }
  4150. if (Isitemadded == false) {
  4151. var IsSpitItem = false;
  4152. var RowTotal = 0;
  4153. var Discount = 0;
  4154. var Qty = 0;
  4155. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  4156. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
  4157. IsSpitItem = true;
  4158. }
  4159. }
  4160. InvoiceItem.Instance().SplitedInvoiceItemList.push({
  4161. orderItemId: itemdata.OrderItemId,
  4162. invoiceItemId: 0,
  4163. itemName: itemdata.ItemName,
  4164. itemId: itemdata.ItemId,
  4165. itemSKU: itemdata.ItemSKU,
  4166. unitName: itemdata.UnitName,
  4167. packSize: itemdata.PackSize,
  4168. packCount: itemdata.PackCount,
  4169. packs: itemdata.Packs,
  4170. quantity: itemdata.Quantity,
  4171. availPacks: itemdata.AvailablePacks,
  4172. availQty: itemdata.AvailableQty,
  4173. listPrice: 0,
  4174. description: itemdata.Description,
  4175. taxGroupName: itemdata.TaxGroupName,
  4176. taxGroupId: itemdata.TaxGroupId,
  4177. isTaxInclusive: $(".dropdown_istaxinclusive").val(),
  4178. addlDiscountPercent: itemdata.AddlDiscountPercent == undefined ? 0 : itemdata.AddlDiscountPercent,
  4179. addlDiscountValue: itemdata.AddlDisountValue,
  4180. creditNote: 0,
  4181. priceListId: 0,
  4182. batchId: 0,
  4183. unitPrice: itemdata.UnitPrice,
  4184. invoiceallocations: null,
  4185. exciseInvoiceItem: null,
  4186. accountId: itemdata.AccountId,
  4187. accountName: itemdata.AccountName,
  4188. walletId: 0,
  4189. Adjustment: 0,
  4190. IsFoc: false,
  4191. TariffNo: "",
  4192. exciseAmount: 0,
  4193. discountName: "",
  4194. discountId: 0,
  4195. refNo: itemdata.RefNo,
  4196. DiscountGroupId: 0,
  4197. DiscountGroupName: "",
  4198. ExchangeItem: false,
  4199. maxQty: itemdata.Quantity,
  4200. RefInvoiceItemId: 0,
  4201. MrpId: itemdata.MrpId,
  4202. taxAdjustment: 0,
  4203. assesableAdjustment: 0,
  4204. inventoryTypeId: itemdata.InventoryTypeId,
  4205. IsBoMItem: false,
  4206. dcItemId: dcItemId,
  4207. TotalRowAmount: 0,
  4208. TotalDiscount: 0,
  4209. TotalAmount: 0,
  4210. BatchId: itemdata.BatchId,
  4211. });
  4212. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  4213. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == itemdata.ItemId) {
  4214. Qty += InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity;
  4215. var rowtotal = Number((InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity * InvoiceItem.Instance().SplitedInvoiceItemList[i].unitPrice) + InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount + itemdata.Adjustment);
  4216. var nonexiceamount = rowtotal - InvoiceItem.Instance().SplitedInvoiceItemList[i].exciseAmount;
  4217. var discount = ((nonexiceamount * itemdata.AddlDiscountPercent) / 100) + (itemdata.Quantity * itemdata.AddlDisountValue);
  4218. InvoiceItem.Instance().SplitedInvoiceItemList[i].TotalAmount = rowtotal,
  4219. InvoiceItem.Instance().SplitedInvoiceItemList[i].TotalDiscount = discount,
  4220. Discount += discount;
  4221. RowTotal += rowtotal;
  4222. }
  4223. }
  4224. $('.item-row').each(function () {
  4225. if ($(this).find('.selectedItemId').val() == itemdata.ItemId) {
  4226. if ($(".hdn_invoicetypeid").val() == "2") {
  4227. $(this).find(".txtRowTotalwithAdjustment").val();
  4228. $(this).find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number(RowTotal), 3));
  4229. }
  4230. else {
  4231. element.find('.prodTotalPrice').text('');
  4232. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
  4233. }
  4234. $(this).find('.prodQuantity').val();
  4235. $(this).find('.prodQuantity').val(Qty);
  4236. $(this).find('#inv_txtdiscount').val();
  4237. $(this).find('#inv_txtdiscount').val(Discount);
  4238. }
  4239. });
  4240. }
  4241. }
  4242. if (orderItemId != 0 && invoiceid == 0) {
  4243. element.find('.prodQuantity').val(itemdata.Quantity);
  4244. }
  4245. element.find(".spn_InvoiceItem").unbind().click(function () {
  4246. InvoiceItem.Instance().createSplitItem(element, itemdata.ItemName + ' - ' + itemdata.ItemSKU, type);
  4247. });
  4248. }
  4249. else if (element.find(".selectedInvoiceItemId").val() == "0" && $('.hdn_invoicetypeid').val() != '3' && $('.hdn_invoicetypeid').val() != '4' && (dcItemId != 0 || (orderItemId != 0 && InvoiceItem.Instance().OrderSettingId == 2))) {
  4250. prodPrice.val(itemdata.UnitPrice);
  4251. prodQty.val(itemdata.Quantity);
  4252. priceListId.val(itemdata.PriceListId);
  4253. element.find('.maxQty').val(itemdata.Quantity);
  4254. }
  4255. if (element.find(".selectedInvoiceItemId").val() == "0" && ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  4256. if (!element.hasClass('SplitItem'))
  4257. prodQty.val(itemdata.Quantity);
  4258. }
  4259. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
  4260. if ((itemdata.IsOfferAvailable == true || itemdata.IsFocAvailable == true) && element.find('.hf_IsFoc').val() != "true") {
  4261. element.find('.btn_offer').removeClass('hidden');
  4262. element.find('.btn_offer').click(function () {
  4263. InvoiceItem.Instance().loadItemOffers(itemdata.ItemId, itemdata.ItemName, invoiceapplytype, contactId, element);
  4264. });
  4265. }
  4266. else
  4267. element.find('.btn_offer').addClass('hidden');
  4268. if (itemdata.IsSpecialPrice == true)
  4269. element.find('.btn_specialPrice').removeClass('hidden');
  4270. }
  4271. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $("#hf_AppSettingName").val() == "Create Return") {
  4272. element.find(".prodTax").empty();
  4273. element.find(".txt_Account").empty();
  4274. if (itemdata.TaxGroupId != 0) {
  4275. element.find(".txtProdTax").val(itemdata.TaxGroupName);
  4276. element.find(".hfProdTax").val(itemdata.TaxGroupId);
  4277. }
  4278. if (itemdata.AccountId != 0) {
  4279. element.find(".hf_Account").val(itemdata.AccountId);
  4280. element.find(".txt_AccountName").val(itemdata.AccountName);
  4281. }
  4282. }
  4283. if (!element.hasClass('SplitItem')) {
  4284. if ($(".hdn_invoiceid").val() != "0" && $(".hdn_invoiceid").val() != undefined) {
  4285. var taxgrpid = element.find(".hfProdTax").val();
  4286. InvoiceItem.Instance().update_tax(element, taxgrpid);
  4287. }
  4288. }
  4289. if (!element.hasClass('SplitItem') && (element.find(".selectedInvoiceItemId").val() == "0" || element.find(".selectedInvoiceItemId").val() == "undefined")) {
  4290. var txtTaxGroup = element.find(".prodTax");
  4291. var hfTaxGroupId = element.find(".hfProdTax");
  4292. if (itemdata.TaxGroupId != 0) {
  4293. txtTaxGroup.empty();
  4294. var selectedTaxgrp = new Option(itemdata.TaxGroupName, itemdata.TaxGroupId, true);
  4295. txtTaxGroup.append(selectedTaxgrp);
  4296. element.find(".txtProdTax").val(itemdata.TaxGroupName);
  4297. hfTaxGroupId.val(itemdata.TaxGroupId);
  4298. InvoiceItem.Instance().update_tax(element, itemdata.TaxGroupId);
  4299. }
  4300. if (itemdata.AccountId != 0) {
  4301. var selectedAccount = new Option(itemdata.AccountName, itemdata.AccountId, true);
  4302. element.find(".txt_Account").empty();
  4303. element.find(".txt_Account").append(selectedAccount);
  4304. element.find(".hf_Account").val(itemdata.AccountId);
  4305. element.find(".txt_AccountName").val(itemdata.AccountName);
  4306. }
  4307. }
  4308. var unit = element.find(".unit");
  4309. unit.text(itemdata.UnitName);
  4310. var sku = element.find(".prodSKU");
  4311. sku.text(itemdata.ItemSKU);
  4312. var packSize = element.find(".packSize");
  4313. if (itemdata.PackSize == "0")
  4314. packSize.val("1");
  4315. else
  4316. packSize.val(itemdata.PackSize);
  4317. if (itemdata.PackCount == "0")
  4318. element.find(".packCount").val("1");
  4319. else
  4320. element.find(".packCount").val(itemdata.PackCount);
  4321. var rowTotal = 0;
  4322. var rowTotalwithAdjustment = 0;
  4323. if (element.find('.prodPrice').val() != undefined && element.find('.prodQuantity').val() != undefined) {
  4324. rowTotal = element.find('.prodPrice').val().replace("$", "") * element.find('.prodQuantity').val();
  4325. rowTotalwithAdjustment = element.find('.prodPrice').val().replace("$", "") * element.find('.prodQuantity').val();
  4326. }
  4327. if (itemdata.InventoryTypeId == 2) {
  4328. element.find('.prodQuantity').removeAttr('readonly');
  4329. }
  4330. var asbAdjAmt = element.find('.hfItemAssesableAdjustmentVal').val();
  4331. if (!isNaN(asbAdjAmt))
  4332. rowTotalwithAdjustment += Number(asbAdjAmt);
  4333. rowTotalwithAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotalwithAdjustment, 2);
  4334. if (isNaN(rowTotal)) {
  4335. if (!element.hasClass('SplitItem')) {
  4336. element.find('.prodTotalPrice').html("N/A");
  4337. element.find('.hfRowTotal').val("0");
  4338. element.find('.hfRowTotalwithAdjustment').val("0");
  4339. }
  4340. }
  4341. else {
  4342. if (!element.hasClass('SplitItem')) {
  4343. element.find('.hfRowTotal').val(rowTotal);
  4344. element.find('.hfRowTotalwithAdjustment').val(rowTotalwithAdjustment);
  4345. element.find('.prodTotalPrice').html(rowTotal);
  4346. }
  4347. }
  4348. if (itemdata.AvailableQty <= 0)
  4349. element.find(".prodAvail").addClass('text-danger');
  4350. else
  4351. element.find(".prodAvail").removeClass('text-danger');
  4352. if (!element.hasClass('SplitItem')) {
  4353. InvoiceItem.Instance().update_row_total(element, false);
  4354. }
  4355. InvoiceItem.Instance().loadPriceLists(element, itemId, itemdata.EnableMrp);
  4356. if (itemdata.EnableMrp != true && itemdata.EnableBatchNo != true && itemdata.EnableSerialNo != true) {
  4357. element.find('.hfRowTotalwithAdjustment').css("text-decoration", "underline");
  4358. element.find('.hfRowTotalwithAdjustment').attr("disabled", false);
  4359. element.find('.Adjustmentrow').click(function () {
  4360. if ($(".hdn_invoicetypeid").val() == "2" && element.find('.selectedInvoiceItemId').val() != "0") {
  4361. InvoiceItem.Instance().editInvItemTaxAllocs(element.find('.selectedInvoiceItemId').val(), element.find('.hfProdTax').val(), element.find('.selectedItemId').val(), element.find('.orderItemId').val(), element);
  4362. }
  4363. });
  4364. }
  4365. else {
  4366. element.find('.hfRowTotalwithAdjustment').css("text-decoration", "");
  4367. element.find('.hfRowTotalwithAdjustment').attr("disabled", true);
  4368. }
  4369. if (IsSpitItem == true) {
  4370. element.remove();
  4371. }
  4372. if (itemdata.IsMultilpeUOMs && $(".hdn_invoicetypeid").val() == "1") {
  4373. element.find(".hf_IsMultipleUOM").val(itemdata.IsMultilpeUOMs);
  4374. let MultipleUOMs = itemdata.MultipleUoms;
  4375. let html = '<option value="0"> -- Select -- </option>';
  4376. for (var i = 0; i < MultipleUOMs.length; i++) {
  4377. html += '<option value="' + MultipleUOMs[i].SchemaDetailId + '">' + MultipleUOMs[i].AlternateUnitName + ' ( ' + MultipleUOMs[i].DefaultSize + ' ' + MultipleUOMs[i].DefaultUnitName + ' ) </option>';
  4378. }
  4379. element.find(".ddl_MultipleUOMs").html(html);
  4380. element.find("#div_MultipleUOMs").removeClass("hidden");
  4381. instance.UOMs.push({
  4382. ItemId: itemId,
  4383. MultipleUOMs: MultipleUOMs
  4384. });
  4385. let SelectedUOM = Number(element.find(".hf_AlternateUnitId").val());
  4386. let DefaultSize = Number(element.find(".hf_DefaultSize").val());
  4387. if (SelectedUOM != 0) {
  4388. element.find(".ddl_MultipleUOMs").val(SelectedUOM);
  4389. let Qty = element.find(".prodQuantity").val();
  4390. let NewQty = Qty / DefaultSize;
  4391. element.find(".prodQuantity").val(NewQty);
  4392. }
  4393. }
  4394. else {
  4395. element.find("#div_MultipleUOMs").addClass("hidden");
  4396. }
  4397. if (itemdata.InventoryTypeId == 1)
  4398. InvoiceItem.Instance().GetDiscounts();
  4399. }, function (response) {
  4400. MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  4401. });
  4402. }
  4403. }
  4404. loadItemOffers(ItemId, ItemName, InvoiceApplyType, OrganizationId, element) {
  4405. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/components/invoices/itemofferselection.js", function () {
  4406. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(0, "", Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance(), function () {
  4407. Bizgaze.Apps.Transact.Components.Invoices.ItemOfferSelection.Instance().LoadOfferItems(OrganizationId, ItemId, ItemName, InvoiceApplyType, element, "Invoice");
  4408. }, Unibase.Platform.Helpers.Size.Large);
  4409. });
  4410. }
  4411. update_tax(element, taxGroupId) {
  4412. var hfTaxValue = element.find(".hfProdTaxValue");
  4413. var hfTaxPercent = element.find(".hfProdTaxPercent");
  4414. var hfProdTax = element.find(".hfProdTax");
  4415. var percentage = 0;
  4416. if (taxGroupId == "0" || taxGroupId == "" || taxGroupId == undefined)
  4417. return percentage;
  4418. let branchid = Number(Unibase.Platform.Membership.Infos.Identity.getSetting("branchid"));
  4419. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().gettaxpercentages(taxGroupId, branchid).then(function (response) {
  4420. var percentstring = "";
  4421. if (response.result.length > 0) {
  4422. var percentages = response.result;
  4423. for (var i = 0; i < percentages.length; i++) {
  4424. percentstring += percentages[i].LedgerId + ":" + percentages[i].Percentage + ",";
  4425. }
  4426. hfTaxPercent.val(percentstring);
  4427. }
  4428. hfTaxValue.val("0");
  4429. InvoiceItem.Instance().update_total();
  4430. InvoiceItem.Instance().TotalAdjustment();
  4431. }, function (response) {
  4432. MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  4433. });
  4434. }
  4435. createSplitItem(element, ItemName, type) {
  4436. let obj = [];
  4437. obj.push({
  4438. type: type,
  4439. element: element,
  4440. });
  4441. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/controls/invoices/splititem.js", function () {
  4442. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(obj, "", Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance(), null, Unibase.Platform.Helpers.Size.Large);
  4443. });
  4444. }
  4445. loadPriceLists(element, itemId, IsEnableMrp) {
  4446. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getLatestMrpByItemId(itemId).then(function (response) {
  4447. if (response.result != null) {
  4448. element.find(".hf_PriceList").val(response.result.PriceListId);
  4449. if (response.result.MrpId != 0 && IsEnableMrp) {
  4450. element.find(".txt_MRP").val(response.result.Mrp);
  4451. element.find(".hfMrpId").val(response.result.MrpId);
  4452. }
  4453. }
  4454. }, function (response) {
  4455. MessageHelper.Instance().showError(JSON.stringify(response.responseJSON.Message), $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  4456. });
  4457. }
  4458. RemoveItem(element) {
  4459. var _this = element.find(".delete");
  4460. var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
  4461. if (invoiceitemid == "0") {
  4462. $(element).find(".prodTax").removeClass("required");
  4463. $(element).find(".txt_Account").removeClass("required");
  4464. $(element).addClass("hidden remove_item");
  4465. $(element).find(".selectedItemId").val(0);
  4466. }
  4467. else {
  4468. _this.parents('.item-row').remove();
  4469. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  4470. }
  4471. InvoiceItem.Instance().update_total();
  4472. InvoiceItem.Instance().TotalAdjustment();
  4473. }
  4474. bind(element, inventoryTypeId) {
  4475. if (inventoryTypeId != 5 && inventoryTypeId != 6 && inventoryTypeId != 7) {
  4476. element.find(".delete").on('click', function () {
  4477. var _this = $(this);
  4478. var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
  4479. if (_this.parents('.item-row').hasClass('SplitItem')) {
  4480. bootbox.confirm("You are about to delete the invoice items. Are you sure?", function (result) {
  4481. if (result == true) {
  4482. var orderid = _this.parents('.item-row').find('.orderItemId').val();
  4483. if ((orderid == 0 || orderid == "0" || orderid == undefined) && _this.parents('.item-row').find('.selectedItemId').val() != 0) {
  4484. let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
  4485. if (index == -1)
  4486. index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
  4487. if (index > -1) {
  4488. InvoiceItem.Instance().itemIds.splice(index, 1);
  4489. }
  4490. }
  4491. else if (orderid != 0) {
  4492. let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
  4493. if (index == -1)
  4494. index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
  4495. if (index > -1) {
  4496. InvoiceItem.Instance().itemIds.splice(index, 1);
  4497. }
  4498. var itemlength = InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.itemId == Number(_this.parents('.item-row').find('.selectedItemId').val()));
  4499. if (itemlength == undefined) {
  4500. if (_this.parents('.item-row').find('.selectedInvoiceItemId').val() != 0) {
  4501. InvoiceItem.Instance().deleted_invoiceItems.push(Number(_this.parents('.item-row').find('.selectedInvoiceItemId').val()));
  4502. }
  4503. }
  4504. }
  4505. var x = [];
  4506. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  4507. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == _this.parents('.item-row').find('.selectedItemId').val()) {
  4508. x.push(i);
  4509. var index = InvoiceItem.Instance().dcItemIds.indexOf(InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId);
  4510. if (index == -1)
  4511. index = InvoiceItem.Instance().dcItemIds.indexOf(Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].dcItemId));
  4512. if (index > -1) {
  4513. InvoiceItem.Instance().dcItemIds.splice(index, 1);
  4514. }
  4515. if (InvoiceItem.Instance().dcItemIds.length == 0)
  4516. InvoiceItem.Instance().dcItemIds = [0];
  4517. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId != 0 && $('#hfInv_IsRetun').val() != "1") {
  4518. InvoiceItem.Instance().deleted_invoiceItems.push(Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].invoiceItemId));
  4519. }
  4520. }
  4521. }
  4522. $('.item-row').each(function () {
  4523. if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true") {
  4524. if ($(this).find('.selectedInvoiceItemId').val() != 0)
  4525. InvoiceItem.Instance().deleted_invoiceItems.push(Number($(this).find('.selectedInvoiceItemId').val()));
  4526. $(this).remove();
  4527. }
  4528. });
  4529. for (var i = x.length - 1; i >= 0; i--) {
  4530. InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
  4531. }
  4532. _this.parents('.item-row').remove();
  4533. $("#txt_Adjustment").val("0");
  4534. InvoiceItem.Instance().update_total();
  4535. InvoiceItem.Instance().TotalAdjustment();
  4536. InvoiceItem.Instance().GetDiscounts();
  4537. }
  4538. });
  4539. }
  4540. else if (invoiceitemid != 0) {
  4541. bootbox.confirm("You are about to delete the invoice items. Are you sure?", function (result) {
  4542. if (result) {
  4543. var invoiceitemid = _this.parents('.item-row').find(".selectedInvoiceItemId").val();
  4544. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  4545. var orderitemid = _this.parents('.item-row').find('.orderItemId').val();
  4546. var dcitemid = _this.parents('.item-row').find('.dcItemId').val();
  4547. if (_this.parents('.item-row').find('.selectedItemId').val() != 0) {
  4548. let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
  4549. if (index == -1)
  4550. index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
  4551. if (index > -1) {
  4552. InvoiceItem.Instance().itemIds.splice(index, 1);
  4553. }
  4554. if (orderitemid != 0 && dcitemid != 0) {
  4555. let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(_this.parents('.item-row').find('.dcItemId').val(), 0);
  4556. if (dcindex == -1)
  4557. dcindex = InvoiceItem.Instance().dcItemIds.indexOf(Number(_this.parents('.item-row').find('.dcItemId').val()), 0);
  4558. InvoiceItem.Instance().dcItemIds.splice(dcindex, 1);
  4559. if (InvoiceItem.Instance().dcItemIds.length == 0)
  4560. InvoiceItem.Instance().dcItemIds.push(0);
  4561. }
  4562. }
  4563. $('.item-row').each(function () {
  4564. if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true")
  4565. $(this).remove();
  4566. });
  4567. _this.parents('.item-row').remove();
  4568. $("#txt_Adjustment").val("0");
  4569. InvoiceItem.Instance().update_total();
  4570. InvoiceItem.Instance().TotalAdjustment();
  4571. InvoiceItem.Instance().GetDiscounts();
  4572. }
  4573. });
  4574. }
  4575. else {
  4576. bootbox.confirm("You are about to delete the invoice item. Are you sure?", function (result) {
  4577. if (result) {
  4578. var dcitemid = _this.parents('.item-row').find('.dcItemId').val();
  4579. if (_this.parents('.item-row').find('.selectedItemId').val() != 0) {
  4580. let index = InvoiceItem.Instance().itemIds.indexOf(_this.parents('.item-row').find('.selectedItemId').val(), 0);
  4581. if (index == -1)
  4582. index = InvoiceItem.Instance().itemIds.indexOf(Number(_this.parents('.item-row').find('.selectedItemId').val()), 0);
  4583. if (index > -1) {
  4584. InvoiceItem.Instance().itemIds.splice(index, 1);
  4585. if (dcitemid != 0) {
  4586. let dcindex = InvoiceItem.Instance().dcItemIds.indexOf(Number(_this.parents('.item-row').find('.dcItemId').val()), 0);
  4587. InvoiceItem.Instance().dcItemIds.splice(dcindex, 1);
  4588. if (InvoiceItem.Instance().dcItemIds.length == 0)
  4589. InvoiceItem.Instance().dcItemIds.push(0);
  4590. }
  4591. }
  4592. }
  4593. var x = [];
  4594. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  4595. if (InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId == _this.parents('.item-row').find('.selectedItemId').val()) {
  4596. x.push(i);
  4597. }
  4598. }
  4599. for (var i = x.length - 1; i >= 0; i--) {
  4600. InvoiceItem.Instance().SplitedInvoiceItemList.splice(x[i], 1);
  4601. }
  4602. $('.item-row').each(function () {
  4603. if ($(this).find('.hfOfferedItemId').val() == _this.parents('.item-row').find('.selectedItemId').val() && $(this).find('.hf_IsFoc').val() == "true")
  4604. $(this).remove();
  4605. });
  4606. _this.parents('.item-row').remove();
  4607. $("#txt_Adjustment").val("0");
  4608. InvoiceItem.Instance().update_total();
  4609. InvoiceItem.Instance().TotalAdjustment();
  4610. InvoiceItem.Instance().GetDiscounts();
  4611. }
  4612. });
  4613. }
  4614. });
  4615. element.find(".prodPrice,.prodQuantity,.exciseAmount").blur(function () {
  4616. InvoiceItem.Instance().update_price(element);
  4617. });
  4618. element.find(".prodQuantity").change(function () {
  4619. InvoiceItem.Instance().CheckOfferForItem($(this));
  4620. });
  4621. element.find(".prodTax").blur(function () {
  4622. InvoiceItem.Instance().update_total();
  4623. InvoiceItem.Instance().TotalAdjustment();
  4624. });
  4625. element.find(".prodPrice").blur(function () {
  4626. InvoiceItem.Instance().update_total();
  4627. InvoiceItem.Instance().TotalAdjustment();
  4628. InvoiceItem.Instance().GetDiscounts();
  4629. });
  4630. element.find(".prodQuantity").blur(function () {
  4631. InvoiceItem.Instance().update_total();
  4632. InvoiceItem.Instance().TotalAdjustment();
  4633. InvoiceItem.Instance().GetDiscounts();
  4634. });
  4635. element.find('.ddl_MultipleUOMs').change(function () {
  4636. InvoiceItem.Instance().update_row_total(element, true);
  4637. });
  4638. element.find(".inv_txtaddldiscount").blur(function () {
  4639. InvoiceItem.Instance().update_total();
  4640. InvoiceItem.Instance().TotalAdjustment();
  4641. InvoiceItem.Instance().GetDiscounts();
  4642. });
  4643. element.find(".inv_txtaddldiscount").blur(InvoiceItem.Instance().update_discount_total);
  4644. element.find(".btnOrder_DiscType").text('Val');
  4645. element.find(".btnInvoice_DiscType").change(function () {
  4646. if (element.find(".btnInvoice_DiscType option:selected").text().trim() == 'Val') {
  4647. element.find('#hfProdDiscountGroupId').val(0);
  4648. element.find('#hfProdDiscountGroupName').val('');
  4649. element.find('.inv_txtaddldiscount').prop('disabled', false);
  4650. }
  4651. else if (element.find(".btnInvoice_DiscType option:selected").text().trim() == '%') {
  4652. element.find('#hfProdDiscountGroupId').val(0);
  4653. element.find('#hfProdDiscountGroupName').val('');
  4654. element.find('.inv_txtaddldiscount').prop('disabled', false);
  4655. if (Number(element.find("#inv_txtdiscount").val()) > 100) {
  4656. element.find("#inv_txtdiscount").val("100");
  4657. }
  4658. }
  4659. InvoiceItem.Instance().update_total();
  4660. InvoiceItem.Instance().TotalAdjustment();
  4661. InvoiceItem.Instance().GetDiscounts();
  4662. });
  4663. }
  4664. else {
  4665. if (inventoryTypeId == 6) {
  4666. element.find(".delete").on('click', function () {
  4667. var dis = $(".fixedvalue").val();
  4668. var _this = $(this);
  4669. var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
  4670. if (selectedinvoiceitemid != 0) {
  4671. bootbox.confirm("You are about to delete the discount item. Are you sure?", function (result) {
  4672. if (result) {
  4673. var rowIndex = element.find(".rowIndex").val();
  4674. var invoiceitemid = _this.parents('.discount-row').find(".selectedInvoiceItemId").val();
  4675. _this.parents('.discount-row').remove();
  4676. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  4677. }
  4678. InvoiceItem.Instance().update_total();
  4679. InvoiceItem.Instance().TotalAdjustment();
  4680. });
  4681. }
  4682. else {
  4683. _this.parents('.discount-row').remove();
  4684. InvoiceItem.Instance().update_total();
  4685. InvoiceItem.Instance().TotalAdjustment();
  4686. }
  4687. InvoiceItem.Instance().update_total();
  4688. InvoiceItem.Instance().TotalAdjustment();
  4689. });
  4690. }
  4691. else if (inventoryTypeId == 5) {
  4692. element.find(".delete").on('click', function () {
  4693. var dis = $(".fixedvalue").val();
  4694. var _this = $(this);
  4695. var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
  4696. if (selectedinvoiceitemid != 0) {
  4697. bootbox.confirm("You are about to delete the coupon item. Are you sure?", function (result) {
  4698. if (result) {
  4699. var rowIndex = element.find(".rowIndex").val();
  4700. var invoiceitemid = _this.parents('.netdiscount-row').find(".selectedInvoiceItemId").val();
  4701. _this.parents('.netdiscount-row').remove();
  4702. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  4703. }
  4704. InvoiceItem.Instance().update_total();
  4705. InvoiceItem.Instance().TotalAdjustment();
  4706. });
  4707. }
  4708. else {
  4709. if (_this.parents('.OnInvoiceOfferItem').length != 0) {
  4710. InvoiceItem.Instance().isOfferChargeApplied = false;
  4711. $(".hdn_isofferchargeapplied").val('false');
  4712. }
  4713. _this.parents('.netdiscount-row').remove();
  4714. InvoiceItem.Instance().update_total();
  4715. InvoiceItem.Instance().TotalAdjustment();
  4716. }
  4717. InvoiceItem.Instance().update_total();
  4718. InvoiceItem.Instance().TotalAdjustment();
  4719. });
  4720. }
  4721. else if (inventoryTypeId == 7) {
  4722. element.find(".delete").on('click', function () {
  4723. var dis = $(".expfixedvalue").val();
  4724. var _this = $(this);
  4725. var selectedinvoiceitemid = element.find(".selectedInvoiceItemId").val();
  4726. if (selectedinvoiceitemid != 0) {
  4727. bootbox.confirm("You are about to delete the coupon item. Are you sure?", function (result) {
  4728. if (result) {
  4729. var rowIndex = element.find(".rowIndex").val();
  4730. var invoiceitemid = _this.parents('.expense-row').find(".selectedInvoiceItemId").val();
  4731. _this.parents('.expense-row').remove();
  4732. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  4733. }
  4734. InvoiceItem.Instance().update_total();
  4735. InvoiceItem.Instance().TotalAdjustment();
  4736. });
  4737. }
  4738. else {
  4739. _this.parents('.expense-row').remove();
  4740. InvoiceItem.Instance().update_total();
  4741. InvoiceItem.Instance().TotalAdjustment();
  4742. }
  4743. InvoiceItem.Instance().update_total();
  4744. InvoiceItem.Instance().TotalAdjustment();
  4745. });
  4746. }
  4747. $(".percentage").on('blur', function () {
  4748. InvoiceItem.Instance().update_discount_total();
  4749. });
  4750. $(".fixedvalue").on('blur', function () {
  4751. InvoiceItem.Instance().update_discount_total();
  4752. });
  4753. $(".expfixedvalue").on('blur', function () {
  4754. InvoiceItem.Instance().update_expense_total();
  4755. });
  4756. $(".exppercentage").on('blur', function () {
  4757. InvoiceItem.Instance().update_expense_total();
  4758. });
  4759. InvoiceItem.Instance().update_discount_total();
  4760. InvoiceItem.Instance().update_expense_total();
  4761. }
  4762. }
  4763. update_price(element) {
  4764. InvoiceItem.Instance().update_row_total(element, true);
  4765. }
  4766. update_row_total(element, checkavailability) {
  4767. var row = element;
  4768. var item = Number(row.find('.selectedItemId').val());
  4769. var inventorytypeid = 0;
  4770. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/inventory/itemmanager.js", function () {
  4771. Bizgaze.Apps.Transact.Managers.ItemManager.Instance().getItem(item).then(function (response) {
  4772. inventorytypeid = response.result.InventoryTypeId;
  4773. if (item == 0) {
  4774. row.find(".prodQuantity").val(0);
  4775. row.find(".prodPrice").val(0);
  4776. MessageHelper.Instance().showError("Please Select Item", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  4777. return false;
  4778. }
  4779. if (checkavailability == true) {
  4780. let BranchId = 0;
  4781. var SettingName = "";
  4782. if ($(".hdn_invoicetypeid").val() == "1") {
  4783. SettingName = "Bizgaze_Extension_Transact_Orders_Setting_Sales_CheckAvailability";
  4784. BranchId = Number($(".txtAutoComplete_billfromaddressid option:selected").val());
  4785. }
  4786. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/managers/orders/ordermanager.js", function () {
  4787. let LobId = Number($(".txtAutoComplete_lobid option:selected").val());
  4788. Bizgaze.Apps.Transact.Managers.OrderManager.Instance().getOrderSettingsByLob(SettingName, LobId, BranchId).then(function (res) {
  4789. let IsCheckAvailability_Lob = res.result.SettingValue;
  4790. if (IsCheckAvailability_Lob == "Yes" || res.result == "") {
  4791. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "4") && (InvoiceItem.Instance().OrderSettingId == 2 || InvoiceItem.Instance().AutoDc == true)) {
  4792. if ($(".hdn_invoiceid").val() == "0") {
  4793. if (Number(row.find('.prodQuantity').val()) > Number(row.find('.prodAvail').text()) && inventorytypeid != 2) {
  4794. MessageHelper.Instance().showError("Check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  4795. if (Number(row.find('.prodAvail').text()) > 0)
  4796. row.find('.prodQuantity').val(row.find('.prodAvail').text());
  4797. else {
  4798. row.find('.prodQuantity').val("0");
  4799. }
  4800. }
  4801. }
  4802. else {
  4803. let Qty = Number(row.find('.prodQuantity').val());
  4804. let AvQty = Number(row.find('.prodAvail').text()) + Number(row.find('.Qty').val());
  4805. if (Qty > AvQty && inventorytypeid != 2) {
  4806. MessageHelper.Instance().showError("Check available quantity", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  4807. row.find('.prodQuantity').val(row.find('.Qty').val());
  4808. }
  4809. }
  4810. }
  4811. if (row.find('.orderItemId').val() != 0 && !row.hasClass('.SplitItem')) {
  4812. if (Number(row.find('.prodQuantity').val()) > Number(row.find('.maxQty').val())) {
  4813. row.find('.prodQuantity').val(Number(row.find('.maxQty').val()));
  4814. InvoiceItem.Instance().update_row_total(element, checkavailability);
  4815. InvoiceItem.Instance().GetDiscounts();
  4816. }
  4817. }
  4818. }
  4819. });
  4820. });
  4821. }
  4822. var rowTotal = 0;
  4823. var rowTotalwithAdjustment = 0;
  4824. if (row.find('.prodPrice').val() != undefined && row.find('.prodQuantity').val() != undefined) {
  4825. rowTotal = row.find('.prodPrice').val().replace("$", "") * (Number(row.find('.prodQuantity').val()));
  4826. rowTotalwithAdjustment = row.find('.prodPrice').val().replace("$", "") * (Number(row.find('.prodQuantity').val()));
  4827. }
  4828. rowTotal += Number(row.find('.hfRowTotalAdjustment').val());
  4829. rowTotalwithAdjustment += Number(row.find('.hfRowTotalAdjustment').val());
  4830. var exciseAmount = element.find(".exciseAmount").val();
  4831. if (exciseAmount != undefined) {
  4832. rowTotal += Number(exciseAmount);
  4833. rowTotalwithAdjustment += Number(exciseAmount);
  4834. }
  4835. var asbAdjAmt = 0;
  4836. asbAdjAmt = row.find('.hfItemAssesableAdjustmentVal').val();
  4837. if (!isNaN(asbAdjAmt))
  4838. rowTotalwithAdjustment += Number(asbAdjAmt);
  4839. rowTotal = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotal, 2);
  4840. rowTotalwithAdjustment = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(rowTotalwithAdjustment, 2);
  4841. if (isNaN(rowTotal)) {
  4842. element.find('.prodTotalPrice').html("N/A");
  4843. element.find('.hfRowTotal').val("0");
  4844. element.find('.hfRowTotalwithAdjustment').val("0");
  4845. }
  4846. else {
  4847. element.find('.hfRowTotal').val(rowTotal);
  4848. element.find('.hfRowTotalwithAdjustment').val(rowTotalwithAdjustment);
  4849. element.find('.prodTotalPrice').html(rowTotal);
  4850. }
  4851. InvoiceItem.Instance().update_total();
  4852. InvoiceItem.Instance().TotalAdjustment();
  4853. InvoiceItem.Instance().update_discount_total();
  4854. InvoiceItem.Instance().update_expense_total();
  4855. });
  4856. });
  4857. }
  4858. CheckOfferForItem(control) {
  4859. var element = control.parents('.item-row');
  4860. if (element.find('.orderItemId').val() == 0) {
  4861. if ($(".hdn_invoicetypeid").val() == "1") {
  4862. if (Number(element.find('.prodQuantity').val()) <= Number(element.find('.prodAvail').text())) {
  4863. InvoiceItem.Instance().GetPlanItems(element.find('.selectedItemId').val(), element.find('.prodQuantity').val(), element);
  4864. }
  4865. }
  4866. else if ($(".hdn_invoicetypeid").val() == "2") {
  4867. InvoiceItem.Instance().GetPlanItems(element.find('.selectedItemId').val(), element.find('.prodQuantity').val(), element);
  4868. }
  4869. }
  4870. }
  4871. GetPlanItems(ItemId, Quantity, element) {
  4872. var contactId = $(".hdn_organizationid").val();
  4873. if (contactId == 0)
  4874. contactId = $(".hfAutoCompleteId_orgcontactid").val();
  4875. var invoiceapplytype = 1;
  4876. var RowTotal = Number(element.find('.prodTotalPrice').text());
  4877. if ($(".hdn_invoicetypeid").val() == "2") {
  4878. invoiceapplytype = 2;
  4879. RowTotal = Number(element.find(".txtRowTotalwithAdjustment").val());
  4880. }
  4881. $('.item-row').each(function () {
  4882. if ($(this).find('.hfOfferedItemId').val() == ItemId) {
  4883. if ($(this).find('.selectedInvoiceItemId').val() != "0")
  4884. InvoiceItem.Instance().deleted_invoiceItems.push(Number($(this).find('.selectedInvoiceItemId').val()));
  4885. $(this).remove();
  4886. }
  4887. });
  4888. let ApplyDate = moment($('.hfdate_journaldate').val().toString(), "YYYY/MM/DD").format("YYYY-MM-DD");
  4889. Bizgaze.Apps.Transact.Managers.OfferManager.Instance().getoffers(ItemId, Number(contactId), Quantity, invoiceapplytype, RowTotal, ApplyDate).then(function (result) {
  4890. var response = result.result;
  4891. if (response.length > 0) {
  4892. for (var j = 0; j < response.length; j++) {
  4893. if (element.hasClass('SplitItem')) {
  4894. var RowTotal = 0;
  4895. var rowDiscount = 0;
  4896. for (var k = 0; k < InvoiceItem.Instance().SplitedInvoiceItemList.length; k++) {
  4897. if (InvoiceItem.Instance().SplitedInvoiceItemList[k].itemId == ItemId) {
  4898. var discValue = 0;
  4899. var discPercent = 0;
  4900. var Itemrow = InvoiceItem.Instance().SplitedInvoiceItemList[k];
  4901. if (response[j].PayoutValue > 0) {
  4902. discValue = response[j].PayoutValue;
  4903. Itemrow.addlDiscountValue = discValue;
  4904. Itemrow.addlDiscountPercent = 0;
  4905. }
  4906. else if (response[j].PayoutPercent > 0) {
  4907. discPercent = response[j].PayoutPercent;
  4908. Itemrow.addlDiscountPercent = discPercent;
  4909. Itemrow.addlDiscountValue = 0;
  4910. }
  4911. var TotalLineAmount = (Number(Itemrow.quantity) * Number(Itemrow.unitPrice)) + Number(Itemrow.exciseAmount) + Number(Itemrow.Adjustment) + Number(Itemrow.assesableAdjustment);
  4912. var NonExciseAmount = TotalLineAmount - Number(Itemrow.exciseAmount);
  4913. var DiscountAmount = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(NonExciseAmount * (Number(Itemrow.addlDiscountPercent) / 100) + (Number(Itemrow.quantity) * Number(Itemrow.addlDiscountValue)), 2);
  4914. Itemrow.DiscountedAmount = DiscountAmount;
  4915. Itemrow.TotalAmount = Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((TotalLineAmount - Number(DiscountAmount)), 3);
  4916. RowTotal += Number(Itemrow.TotalAmount);
  4917. rowDiscount += Number(DiscountAmount);
  4918. }
  4919. }
  4920. if ($(".hdn_invoicetypeid").val() == "2") {
  4921. element.find(".txtRowTotalwithAdjustment").val();
  4922. element.find(".txtRowTotalwithAdjustment").val(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
  4923. element.find('#inv_txtdiscount').val();
  4924. element.find('#inv_txtdiscount').val(rowDiscount);
  4925. }
  4926. else {
  4927. element.find('.prodTotalPrice').text('');
  4928. element.find('.prodTotalPrice').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(RowTotal, 3));
  4929. element.find('#inv_txtdiscount').val();
  4930. element.find('#inv_txtdiscount').val(rowDiscount);
  4931. }
  4932. }
  4933. else {
  4934. var discValue = 0;
  4935. var discPercent = 0;
  4936. if (response[j].PayoutValue > 0) {
  4937. discValue = response[j].PayoutValue;
  4938. element.find(".btnInvoice_DiscType option[value='Val']").prop("selected", true);
  4939. element.find('.inv_txtaddldiscount').val(discValue);
  4940. }
  4941. else if (response[j].PayoutPercent > 0) {
  4942. discPercent = response[j].PayoutPercent;
  4943. element.find(".btnInvoice_DiscType option[value='%']").prop("selected", true);
  4944. element.find('.inv_txtaddldiscount').val(discPercent);
  4945. }
  4946. }
  4947. if (response[j].ItemVolumePayouts.length > 0) {
  4948. var OfferItems = response[j].ItemVolumePayouts;
  4949. for (var i = 0; i < OfferItems.length; i++) {
  4950. var emptyRow = {
  4951. orderItemId: 0,
  4952. invoiceItemId: 0,
  4953. itemName: OfferItems[i].ItemName,
  4954. itemId: OfferItems[i].ItemId,
  4955. itemSKU: "",
  4956. unitName: "",
  4957. packSize: 0,
  4958. packCount: 0,
  4959. packs: 0,
  4960. quantity: OfferItems[i].Quantity,
  4961. availPacks: 0,
  4962. availQty: 0,
  4963. listPrice: 0,
  4964. description: OfferItems[i].Description,
  4965. taxGroupName: "",
  4966. taxGroupId: 0,
  4967. isTaxInclusive: $("#hfIsTaxInclusive").val(),
  4968. addlDiscountPercent: OfferItems[i].Discount,
  4969. addlDiscountValue: 0,
  4970. creditNote: 0,
  4971. priceListId: 0,
  4972. batchId: 0,
  4973. unitPrice: 0,
  4974. invoiceallocations: null,
  4975. exciseInvoiceItem: null,
  4976. accountId: 0,
  4977. accountName: "",
  4978. walletId: 0,
  4979. Adjustment: 0,
  4980. TariffNo: "",
  4981. exciseAmount: 0,
  4982. discountName: "",
  4983. discountId: 0,
  4984. refNo: "",
  4985. DiscountGroupId: 0,
  4986. DiscountGroupName: '',
  4987. RefInvoiceItemId: 0,
  4988. MrpId: 0,
  4989. taxAdjustment: 0,
  4990. assesableAdjustment: 0,
  4991. inventoryTypeId: 0,
  4992. dcItemId: 0,
  4993. TotalRowAmount: 0,
  4994. maxQty: 0,
  4995. OfferItemId: ItemId,
  4996. IsFoc: true,
  4997. };
  4998. InvoiceItem.Instance().addDataRow(emptyRow, false);
  4999. }
  5000. }
  5001. }
  5002. }
  5003. });
  5004. }
  5005. TotalAdjustment() {
  5006. if ($('#chk_AutoAdjustment').is(':checked')) {
  5007. var total = $('.nettotal').text();
  5008. var splitTotal = total.split('.');
  5009. var AdjustmentValue = 0;
  5010. var splitedAdjestment = 0;
  5011. $("#txt_Adjustment").val(0);
  5012. $(".hdn_adjustment").val(0);
  5013. if (!isNaN(Number($('#txt_Adjustment').val()))) {
  5014. AdjustmentValue = Number($('#txt_Adjustment').val());
  5015. }
  5016. if (Number(splitTotal[1]) > 0) {
  5017. if (Number(splitTotal[1]) >= 50) {
  5018. splitedAdjestment = (100 - Number(splitTotal[1])) / 100;
  5019. AdjustmentValue += splitedAdjestment;
  5020. $('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2)).blur();
  5021. $(".hdn_adjustment").val($('#txt_Adjustment').val());
  5022. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(AdjustmentValue, 2));
  5023. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(total) + AdjustmentValue), 2));
  5024. }
  5025. else {
  5026. splitedAdjestment = Number(splitTotal[1]) / 100;
  5027. AdjustmentValue -= splitedAdjestment;
  5028. $('#txt_Adjustment').val(Number(AdjustmentValue).toFixed(2));
  5029. $(".hdn_adjustment").val($('#txt_Adjustment').val());
  5030. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(AdjustmentValue, 2));
  5031. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number(total) + AdjustmentValue), 2));
  5032. }
  5033. }
  5034. }
  5035. else {
  5036. $("#span_Adjustment").text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(Number($('#txt_Adjustment').val()), 2));
  5037. $('.nettotal').text(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber((Number($('.nettotal').text()) + Number($('#txt_Adjustment').val())), 2));
  5038. }
  5039. }
  5040. update_discount_total() {
  5041. var item_total = Number($("#grosstotal").html()) - Number($("#totalItemDiscount").html());
  5042. var nettotal = Number($("#totalTax").text()) + Number(item_total);
  5043. var sub_dis_total = 0;
  5044. var prev_dis_total = 0;
  5045. $(".discount-row,.netdiscount-row").each(function () {
  5046. if ($(this).find(".percentage").val() != undefined) {
  5047. var ele = $(this);
  5048. var tt = prev_dis_total;
  5049. if (!isNaN(tt))
  5050. sub_dis_total += Number(tt);
  5051. var percent = ele.find(".percentage").val();
  5052. var value = ele.find(".fixedvalue").val();
  5053. var adjustment = 0;
  5054. if (percent == "")
  5055. percent = 0;
  5056. if (value == "")
  5057. value = 0;
  5058. var totaldiscount = 0;
  5059. var totalElement = $(this).find(".netdiscount-row-total");
  5060. if (totalElement.length != 0) {
  5061. totaldiscount = (Number(percent) * Number(nettotal - sub_dis_total) / 100) + Number(value) + Number(adjustment);
  5062. }
  5063. else
  5064. totaldiscount = (Number(percent) * Number(item_total - sub_dis_total) / 100) + Number(value) + Number(adjustment);
  5065. ele.find(".discount-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaldiscount, 2));
  5066. ele.find(".netdiscount-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totaldiscount, 2));
  5067. prev_dis_total = totaldiscount;
  5068. }
  5069. });
  5070. InvoiceItem.Instance().update_total();
  5071. InvoiceItem.Instance().TotalAdjustment();
  5072. }
  5073. update_expense_total() {
  5074. var item_total = Number($("#grosstotal").html()) - Number($("#totalItemDiscount").html());
  5075. var nettotal = Number($("#totalTax").text()) + Number(item_total);
  5076. var sub_dis_total = 0;
  5077. var prev_dis_total = 0;
  5078. $(".expense-row").each(function () {
  5079. if ($(this).find(".exppercentage").val() != undefined) {
  5080. var ele = $(this);
  5081. var tt = prev_dis_total;
  5082. if (!isNaN(tt))
  5083. sub_dis_total += Number(tt);
  5084. var percent = ele.find(".exppercentage").val();
  5085. var value = ele.find(".expfixedvalue").val();
  5086. var adjustment = 0;
  5087. if (percent == "")
  5088. percent = 0;
  5089. if (value == "")
  5090. value = 0;
  5091. var totalexpense = (Number(percent) * Number(nettotal - sub_dis_total) / 100) + Number(value) + Number(adjustment);
  5092. ele.find(".expense-row-total").html(Unibase.Core.Helpers.NumberHelper.Instance().roundNumber(totalexpense, 2));
  5093. prev_dis_total = totalexpense;
  5094. }
  5095. });
  5096. InvoiceItem.Instance().update_total();
  5097. InvoiceItem.Instance().TotalAdjustment();
  5098. }
  5099. RefreshItemRowDetaisl(element) {
  5100. if (element.filter('.SplInvoiceItemRow').length > 0) {
  5101. Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance().update_Discount(element);
  5102. var row = InvoiceItem.Instance().SplitedInvoiceItemList.find(x => x.invoiceItemId == element.find(".hf_selectedInvoiceItemId").val());
  5103. if (row != undefined) {
  5104. row.assesableAdjustment = element.find('.hf_ItemAssesableAdjustmentVal').val();
  5105. row.TotalAmount = element.find(".hf_RowTotal").val();
  5106. }
  5107. Bizgaze.Apps.Transact.Controls.Invoices.SplitItem.Instance().updateQuantity();
  5108. InvoiceItem.Instance().update_total();
  5109. }
  5110. else {
  5111. InvoiceItem.Instance().update_total();
  5112. }
  5113. }
  5114. editInvItemTaxAllocs(invoiceItemId, taxGroupId, itemId, orderItemId, element) {
  5115. var prvs = InvoiceItem.Instance().invItemTaxAdjustmentList;
  5116. var obj = {
  5117. invoiceItemId: invoiceItemId,
  5118. taxGroupId: taxGroupId,
  5119. itemId: itemId,
  5120. orderItemId: orderItemId,
  5121. element: element,
  5122. };
  5123. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/transact/components/invoices/invoiceitemtaxalloc.js", function () {
  5124. Unibase.Platform.Helpers.NavigationHelper.Instance().popup(obj, "", Bizgaze.Apps.Transact.Components.Invoices.InvoiceItemTaxAloc.Instance(), null, Unibase.Platform.Helpers.Size.Large);
  5125. });
  5126. InvoiceItem.Instance().invItemTaxAdjustmentList = prvs;
  5127. }
  5128. GetCustomerTurnOver() {
  5129. $(".txt_tcsadjustment").val("0");
  5130. $("#chk_tcsapplied").unbind();
  5131. $(".number_tcsamount").prop("disabled", true);
  5132. $(".div_tcsadjustment").addClass("floating-label-form-group-with-value");
  5133. $("#chk_tcsapplied").change(function () {
  5134. if ($(this).prop('checked') == true && InvoiceItem.Instance().EnableTenantTcs == false && ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4")) {
  5135. MessageHelper.Instance().showError("Please Submit TCS Declaration", $("#form-container-" + $("#hf_FormId").val()).find(".bizgaze_FormErrorMessages").attr('id'));
  5136. $("#hdnchk_tcsapplied").val("false");
  5137. $('#chk_tcsapplied').prop('checked', false);
  5138. }
  5139. else {
  5140. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  5141. $("#txt_Adjustment").val(0);
  5142. $(".hdn_adjustment").val(0);
  5143. }
  5144. if ($(this).prop('checked') == true && $(".hdn_invoicetypeid").val() == "1") {
  5145. bootbox.confirm("Confirm if sale value is > 50,00,000 for this customer.In this current Financial Year.", function (result) {
  5146. if (result) {
  5147. $("#div_tcstaxrate").removeClass("hidden");
  5148. $(".div_tcsadjustment").removeClass("hidden");
  5149. $("#div_tcsamount").removeClass("hidden");
  5150. InvoiceItem.Instance().update_total();
  5151. InvoiceItem.Instance().TotalAdjustment();
  5152. }
  5153. else {
  5154. $("#div_tcstaxrate").addClass("hidden");
  5155. $(".div_tcsadjustment").addClass("hidden");
  5156. $("#div_tcsamount").addClass("hidden");
  5157. $('#chk_tcsapplied').prop('checked', false);
  5158. $("#hdnchk_tcsapplied").val("false");
  5159. InvoiceItem.Instance().update_total();
  5160. InvoiceItem.Instance().TotalAdjustment();
  5161. }
  5162. });
  5163. }
  5164. else if ($(this).prop('checked') == true) {
  5165. $("#div_tcstaxrate").removeClass("hidden");
  5166. $(".div_tcsadjustment").removeClass("hidden");
  5167. $("#div_tcsamount").removeClass("hidden");
  5168. InvoiceItem.Instance().update_total();
  5169. InvoiceItem.Instance().TotalAdjustment();
  5170. }
  5171. else {
  5172. $("#div_tcstaxrate").addClass("hidden");
  5173. $(".div_tcsadjustment").addClass("hidden");
  5174. $("#div_tcsamount").addClass("hidden");
  5175. InvoiceItem.Instance().update_total();
  5176. InvoiceItem.Instance().TotalAdjustment();
  5177. }
  5178. }
  5179. });
  5180. $(".txt_tcsadjustment").unbind();
  5181. $(".txt_tcsadjustment").blur(function () {
  5182. if ($('#chk_AutoAdjustment').prop("checked") == true) {
  5183. $("#txt_Adjustment").val(0);
  5184. $(".hdn_adjustment").val(0);
  5185. }
  5186. InvoiceItem.Instance().update_total();
  5187. InvoiceItem.Instance().TotalAdjustment();
  5188. });
  5189. $("#div_tcstaxrate").addClass("hidden");
  5190. $(".div_tcsadjustment").addClass("hidden");
  5191. $("#div_tcsamount").addClass("hidden");
  5192. $("#chk_tcsapplied").prop("checked", false);
  5193. $("#chk_tcsapplied").prop("disabled", false);
  5194. 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) {
  5195. if (response.result != null) {
  5196. $(".number_tcstaxrate").val(response.result.TaxRate);
  5197. if (response.result.TCSTaxCodeId != 0) {
  5198. $(".hdn_tcstaxcodeid").val(response.result.TCSTaxCodeId);
  5199. $(".hdn_tcstaxcodeaccountid").val(response.result.TCSTaxCodeAccountId);
  5200. $(".number_tcstaxrate").prop("disabled", true);
  5201. }
  5202. InvoiceItem.Instance().TurnOver = response.result.TurnOver;
  5203. InvoiceItem.Instance().ContactTcsEnable = response.result.Enable;
  5204. InvoiceItem.Instance().EnableTenantTcs = response.result.EnableTenantTcs;
  5205. InvoiceItem.Instance().PanAvailable = response.result.PanAvailable;
  5206. InvoiceItem.Instance().TaxRate = response.result.TaxRate;
  5207. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "2") {
  5208. if (InvoiceItem.Instance().ContactTcsEnable == true && InvoiceItem.Instance().EnableTenantTcs == true) {
  5209. $("#chk_tcsapplied").prop("checked", true);
  5210. $("#hdnchk_tcsapplied").val("true");
  5211. $("#div_tcstaxrate").removeClass("hidden");
  5212. $(".div_tcsadjustment").removeClass("hidden");
  5213. $("#div_tcsamount").removeClass("hidden");
  5214. $(".number_tcsamount").prop("disabled", true);
  5215. }
  5216. else if (InvoiceItem.Instance().TurnOver > 5000000 && $(".hdn_invoicetypeid").val() == "1") {
  5217. $("#chk_tcsapplied").prop("checked", true);
  5218. $("#chk_tcsapplied").prop("disabled", "disabled");
  5219. $("#hdnchk_tcsapplied").val("true");
  5220. $("#div_tcstaxrate").removeClass("hidden");
  5221. $(".div_tcsadjustment").removeClass("hidden");
  5222. $("#div_tcsamount").removeClass("hidden");
  5223. $(".number_tcsamount").prop("disabled", true);
  5224. }
  5225. }
  5226. else if ($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4" || $(".hdn_invoicetypeid").val() == "6" || $(".hdn_invoicetypeid").val() == "7") {
  5227. $("#chk_tcsapplied").prop("checked", false);
  5228. $("#hdnchk_tcsapplied").val("false");
  5229. $("#div_tcstaxrate").addClass("hidden");
  5230. $(".div_tcsadjustment").addClass("hidden");
  5231. $("#div_tcsamount").addClass("hidden");
  5232. }
  5233. if (($(".hdn_invoicetypeid").val() == "3" || $(".hdn_invoicetypeid").val() == "4") && $('#hfInv_RefInvoiceId').val() == 0 && $("#hf_AppSettingName").val() == "Create Return") {
  5234. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getInvoiceDetails(($(".hdn_invoicetypeid").val())).then(function (res) {
  5235. if (res.result != null && res.result != "") {
  5236. InvoiceItem.Instance().TaxRate = res.result.TcsTaxRate;
  5237. $(".number_tcstaxrate").val(res.result.TcsTaxRate);
  5238. $(".hdn_tcstaxcodeid").val(response.result.TcsTaxCodeId);
  5239. if (res.result.TcsTaxCodeId != 0) {
  5240. $(".number_tcstaxrate").prop("disabled", true);
  5241. }
  5242. $(".number_tcsamount").prop("disabled", true);
  5243. }
  5244. });
  5245. }
  5246. }
  5247. });
  5248. }
  5249. bindContactName() {
  5250. Unibase.Platform.Forms.Managers.TagManager.Instance().GetTagItemsByUserId(Unibase.Platform.Membership.Infos.Identity.getCurrentUser().userId).then(function (response) {
  5251. if (response.result.length == 1) {
  5252. InvoiceItem.instance.fileCacheHelper.loadJsFile("apps/crm/lobs/managers/lobmanager.js", function () {
  5253. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobByTagGroupId(response.result[0].TagGroupId).then(function (res) {
  5254. let LobId = res.result.LobId;
  5255. Bizgaze.Apps.CRM.Lobs.Managers.LobManager.Instance().getLobByLobId(LobId).then(function (result) {
  5256. if (result.result != null) {
  5257. if (result.result.DefaultContactId != 0) {
  5258. Unibase.Platform.Helpers.FileCacheHelper.Instance().loadJsFile("apps/crm/contacts/managers/contactmanager.js", function () {
  5259. Bizgaze.Apps.Crm.Contacts.Managers.ContactManager.Instance().getOrgContact(result.result.DefaultContactId).then(function (response) {
  5260. if (response.result != null) {
  5261. if (response.result.OrgContactName == null)
  5262. response.result.OrgContactName = "";
  5263. var _Name = new Option(response.result.OrgContactName, response.result.OrgContactId.toString(), false, false);
  5264. $(".txtAutoComplete_orgcontactid").append(_Name).trigger("change");
  5265. $(".hfAutoCompleteId_orgcontactid").val(response.result.OrgContactId);
  5266. InvoiceItem.Instance().LoadContactDetails();
  5267. }
  5268. });
  5269. });
  5270. }
  5271. }
  5272. });
  5273. });
  5274. });
  5275. }
  5276. });
  5277. }
  5278. GetDiscounts() {
  5279. if (($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3")) {
  5280. let contactid = Number($(".hdn_organizationid").val());
  5281. let invoicedate = moment($('.date_journaldate').val().toString(), "DD/MM/YYYY").format("YYYY-MM-DD");
  5282. if ($(".hdn_invoicetypeid").val() == "3")
  5283. invoicedate = moment($('.date_refdate').val().toString(), "DD/MM/YYYY").format("YYYY-MM-DD");
  5284. var ItemList = [];
  5285. $(".InvoiceItems").find(".item-row").each(function () {
  5286. if (!$(this).hasClass('SplitItem')) {
  5287. if ($(this).find(".selectedItemId").val() != undefined && $(this).find(".selectedItemId").val() != 0) {
  5288. var Quantity = Number($(this).find(".prodQuantity").val());
  5289. let ItemId = Number($(this).find(".selectedItemId").val());
  5290. ItemList.push({
  5291. ItemId: ItemId,
  5292. Quantity: Number(Quantity),
  5293. ContactId: contactid,
  5294. InvoiceDate: invoicedate
  5295. });
  5296. }
  5297. }
  5298. });
  5299. for (var i = 0; i < InvoiceItem.Instance().SplitedInvoiceItemList.length; i++) {
  5300. ItemList.push({
  5301. ItemId: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].itemId),
  5302. Quantity: Number(InvoiceItem.Instance().SplitedInvoiceItemList[i].quantity),
  5303. ContactId: contactid,
  5304. InvoiceDate: invoicedate
  5305. });
  5306. }
  5307. Bizgaze.Apps.Transact.Managers.OfferManager.Instance().getdiscounts(ItemList).then(function (response) {
  5308. var data = response.result;
  5309. var InvItemId = 0;
  5310. var discription = "";
  5311. if ($(".netdiscount-row[style='pointer-events:none']").length == 0 && $(".hdn_invoicetypeid").val() == "3") {
  5312. InvoiceItem.Instance().isOfferChargeApplied = false;
  5313. if (data != null)
  5314. data.PayoutValue == 0;
  5315. }
  5316. $('.netdiscount-row').each(function () {
  5317. var invoiceitemid = $(this).find(".selectedInvoiceItemId").val();
  5318. 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()))) {
  5319. $(this).remove();
  5320. if (invoiceitemid != undefined || invoiceitemid != 0) {
  5321. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  5322. InvItemId = Number(invoiceitemid);
  5323. discription = $(this).find('.discountDesc').val().toString();
  5324. }
  5325. InvoiceItem.Instance().update_total();
  5326. InvoiceItem.Instance().TotalAdjustment();
  5327. }
  5328. });
  5329. if (data != null && data.PayoutValue == 0) {
  5330. if ($(".netdiscount-row[style='pointer-events:none']").length > 0) {
  5331. var invoiceitemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedInvoiceItemId").val();
  5332. $(".netdiscount-row[style='pointer-events:none']").remove();
  5333. if (invoiceitemid != undefined || invoiceitemid != 0) {
  5334. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  5335. InvItemId = Number(invoiceitemid);
  5336. $(".hdn_isofferchargeapplied").val('false');
  5337. }
  5338. InvoiceItem.Instance().update_total();
  5339. InvoiceItem.Instance().TotalAdjustment();
  5340. }
  5341. }
  5342. if ((data != null && data.PayoutValue > 0)) {
  5343. if ($(".netdiscount-row[style='pointer-events:none']").length > 0) {
  5344. var itemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedItemId").val();
  5345. if (data.ItemId != itemid) {
  5346. var invoiceitemid = $(".netdiscount-row[style='pointer-events:none']").find(".selectedInvoiceItemId").val();
  5347. $(".netdiscount-row[style='pointer-events:none']").remove();
  5348. if (invoiceitemid != undefined || invoiceitemid != 0) {
  5349. InvoiceItem.Instance().deleted_invoiceItems.push(Number(invoiceitemid));
  5350. InvItemId = Number(invoiceitemid);
  5351. }
  5352. InvoiceItem.Instance().update_total();
  5353. InvoiceItem.Instance().TotalAdjustment();
  5354. }
  5355. }
  5356. let Index = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().deleted_invoiceItems.findIndex(x => x == InvItemId);
  5357. if (Index != -1) {
  5358. Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance().deleted_invoiceItems.splice(Index, 1);
  5359. }
  5360. var itemRow = {
  5361. orderItemId: 0,
  5362. invoiceItemId: InvItemId,
  5363. itemName: data.ItemName,
  5364. itemId: data.ItemId,
  5365. itemSKU: '',
  5366. unitName: "",
  5367. packSize: 0,
  5368. packCount: 0,
  5369. packs: 0,
  5370. quantity: 0,
  5371. availPacks: 0,
  5372. availQty: 0,
  5373. listPrice: 0,
  5374. description: discription,
  5375. taxGroupName: "",
  5376. taxGroupId: 0,
  5377. isTaxInclusive: $("#hf_istaxinclusive").val(),
  5378. addlDiscountPercent: 0,
  5379. addlDiscountValue: data.PayoutValue,
  5380. creditNote: 0,
  5381. priceListId: 0,
  5382. batchId: 0,
  5383. unitPrice: 0,
  5384. invoiceallocations: null,
  5385. exciseInvoiceItem: null,
  5386. accountId: 0,
  5387. accountName: "",
  5388. walletId: 0,
  5389. Adjustment: 0,
  5390. IsFoc: false,
  5391. TariffNo: "",
  5392. exciseAmount: 0,
  5393. discountName: "",
  5394. discountId: 0,
  5395. refNo: "",
  5396. DiscountGroupId: 0,
  5397. DiscountGroupName: '',
  5398. RefInvoiceItemId: 0,
  5399. MrpId: 0,
  5400. taxAdjustment: 0,
  5401. assesableAdjustment: 0,
  5402. inventoryTypeId: 5,
  5403. dcItemId: 0,
  5404. TotalRowAmount: 0,
  5405. maxQty: 0,
  5406. OfferItemId: 0
  5407. };
  5408. InvoiceItem.instance.addDataRow(itemRow, false);
  5409. }
  5410. });
  5411. }
  5412. }
  5413. GetOnInvoiceDiscountItem(element) {
  5414. if ($(".hdn_invoicetypeid").val() == "1" || $(".hdn_invoicetypeid").val() == "3") {
  5415. var itemid = element.find('.selectedItemId').val();
  5416. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getItemById(Number(itemid)).then(function (response) {
  5417. var data = response.result;
  5418. let invoiceid = $(".hdn_invoiceid").val();
  5419. if (invoiceid == undefined || invoiceid == "null")
  5420. invoiceid = 0;
  5421. if (data != null && !data.Sellable && !data.Purchasable)
  5422. element.attr("style", "pointer-events:none");
  5423. if (invoiceid == "0")
  5424. element.addClass("OnInvoiceOfferItem");
  5425. });
  5426. }
  5427. }
  5428. IsCustomerIndustrial(LobId, OrganizationId) {
  5429. var url1 = "apis/v4/bizgaze/transact/invoice/checkisenablesalespipeline/invoicetype/" + $(".hdn_invoicetypeid").val() + "/lobid/" + LobId + "/organizationid/" + OrganizationId;
  5430. Bizgaze.Apps.Transact.Managers.InvoiceManager.Instance().getIsEnableSalesPipeline(url1).then(function (response) {
  5431. if (response.result == false) {
  5432. $(".section_Ebs").addClass("hidden");
  5433. }
  5434. else {
  5435. $(".section_Ebs").removeClass("hidden");
  5436. }
  5437. });
  5438. }
  5439. loadChangeTaxGroupAutoComplete() {
  5440. var hfTaxgroup = $("#hdn_changetaxgroup");
  5441. AutoCompleteHelper.getHelper().Create("#change_taxgroup", hfTaxgroup, _appsettings.server_url() + "/apis/v4/bizgaze/transact/tax/taxgroupautocomplete", function (result) {
  5442. });
  5443. }
  5444. ShowOrHideEInvoiceButton() {
  5445. let instance = Bizgaze.Apps.Transact.Controls.InvoiceItem.Instance();
  5446. var installedAppId = Unibase.Themes.Providers.DetailHelper.installedAppId;
  5447. var invoiceid = Number(Unibase.Themes.Providers.Detail_Settings.Instance().InputParameters.find(x => x.Key == "hf_" + installedAppId + "_invoiceid").Value);
  5448. instance.fileCacheHelper.loadJsFiles(["apps/transact/managers/einvoice/einvoicemanager.js"], function () {
  5449. Bizgaze.Apps.Transact.Managers.EInvoiceManager.Instance().geteinvoicebyinvoiceid(invoiceid).then(function (res) {
  5450. if (res.result != null) {
  5451. if (res.result.EInvoiceStatusId == 2 || res.result.AckNo == null)
  5452. $(".DetailSetting_" + installedAppId + "_e-Invoice").removeClass("hidden");
  5453. else
  5454. $(".DetailSetting_" + installedAppId + "_e-Invoice").addClass("hidden");
  5455. }
  5456. });
  5457. });
  5458. }
  5459. static Instance() {
  5460. if (this.instance === undefined) {
  5461. this.instance = new InvoiceItem();
  5462. }
  5463. return this.instance;
  5464. }
  5465. }
  5466. Controls.InvoiceItem = InvoiceItem;
  5467. })(Controls = Transact.Controls || (Transact.Controls = {}));
  5468. })(Transact = Apps.Transact || (Apps.Transact = {}));
  5469. })(Apps = Bizgaze.Apps || (Bizgaze.Apps = {}));
  5470. })(Bizgaze || (Bizgaze = {}));