CartViewController.m 246 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346
  1. //
  2. // CartViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-6.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RAUtils.h"
  9. #import "CartViewController.h"
  10. #import "ModelItemCell.h"
  11. #import "RANetwork.h"
  12. //#import "CommonGridViewController.h"
  13. #import "CreateOrderViewController.h"
  14. #import "DetailViewController.h"
  15. #import "EditModelPriceViewController.h"
  16. #import "MainViewController.h"
  17. #import "LoginViewController.h"
  18. #import "ItemNotesViewController.h"
  19. #import "CartGeneralNotesViewController.h"
  20. #import "DefaultAppearance.h"
  21. #import "DefaultTableHeaderView.h"
  22. #import "SortItemViewController.h"
  23. #import "SortButton.h"
  24. #import "NotificationNameCenter.h"
  25. #import "RASingleton.h"
  26. #import "JKMessageBoxController.h"
  27. #import "RAPDFViewController.h"
  28. #ifdef SCANNER_ORDER
  29. #import "ScanCartItemCell.h"
  30. #import "ScanDiscountViewController.h"
  31. #else
  32. #endif
  33. #ifdef BUILD_CONTRAST
  34. #import "OrderDiscountViewController.h"
  35. #endif
  36. #ifdef BACKORDER_PROCESS
  37. #import "RAOrderEditorViewController.h"
  38. #endif
  39. #import "CustomerEditViewController.h"
  40. //#define ALERT_FREE 1024
  41. //#define ALERT_DEL 1025
  42. //#define ALERT_SET_FREE 1026
  43. //#define ALERT_RESTORE_FREE 1027
  44. @interface CartViewController ()
  45. {
  46. CGRect cancelButtonFrame;
  47. }
  48. @property (nonatomic,strong) SortItemViewController *sortItemController;
  49. @property (nonatomic,assign) int sortIndex;
  50. @property (nonatomic,strong) SortButton *sortButton;
  51. @property (strong, nonatomic) IBOutlet UIButton *placeOrderButton;
  52. @property (strong, nonatomic) IBOutlet UIButton *cancelOrderButton;
  53. @property (nonatomic,strong) NSOperationQueue *dataOperationQueue;
  54. @property (strong, nonatomic) IBOutlet UIButton *emailButton;
  55. @property (strong, nonatomic) IBOutlet UIButton *printButton;
  56. @property (weak, nonatomic) IBOutlet UIButton *editButton;
  57. @property (weak, nonatomic) IBOutlet UIButton *continueButton;
  58. @property (weak, nonatomic) IBOutlet UILabel *labelTotalcuft;
  59. @property (weak, nonatomic) IBOutlet UILabel *labelTotalWeight;
  60. @property (weak, nonatomic) IBOutlet UILabel *labelTotalCarton;
  61. @property (weak, nonatomic) IBOutlet UILabel *valuecuft;
  62. @property (weak, nonatomic) IBOutlet UILabel *valueweight;
  63. @property (weak, nonatomic) IBOutlet UILabel *valuecarton;
  64. @property (nonatomic,assign) BOOL currentOrderIsMerged;
  65. @property (nonatomic,strong) DefaultTableHeaderView *cartIndicatorBar;
  66. @property (nonatomic,assign) BOOL back_order_flag;
  67. @property (nonatomic,strong) NSDictionary *cart_json;
  68. @property (nonatomic,copy) NSString *print_url;
  69. @property (nonatomic,assign) BOOL available;///<所有Model均有库存,才能Place Order。
  70. @end
  71. @implementation CartViewController
  72. - (NSOperationQueue *)dataOperationQueue {
  73. if (!_dataOperationQueue) {
  74. _dataOperationQueue = [[NSOperationQueue alloc] init];
  75. _dataOperationQueue.maxConcurrentOperationCount = 1;
  76. }
  77. return _dataOperationQueue;
  78. }
  79. - (void)dealloc {
  80. #ifndef RA_NOTIFICATION
  81. [[NSNotificationCenter defaultCenter] removeObserver:self];
  82. #endif
  83. }
  84. -(void) logout
  85. {
  86. [super logout];
  87. [self.content_arr removeAllObjects];
  88. [self refresh_ui];
  89. self.cart_json = nil;
  90. }
  91. - (IBAction)OnEditSelectClick:(id)sender {
  92. NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  93. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  94. if(count==0)
  95. {
  96. [RAUtils message_alert:@"No item in the cart" title:@"Cart" controller:self] ;
  97. return;
  98. }
  99. for(int i=0;i<count;i++)
  100. {
  101. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  102. [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  103. }
  104. NSString * ids = [arr_ids componentsJoinedByString:@","];
  105. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select all model and" message:nil preferredStyle:UIAlertControllerStyleAlert];
  106. //block代码块取代了delegate
  107. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  108. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove all models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  109. //block代码块取代了delegate
  110. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  111. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart" completion:^{
  112. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  113. NSMutableDictionary* cart_json =result;
  114. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  115. [waitalert dismissViewControllerAnimated:YES completion:^{
  116. if([[cart_json valueForKey:@"result"] intValue]==2)
  117. {
  118. [self end_edit];
  119. #ifdef RA_NOTIFICATION
  120. [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  121. #else
  122. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  123. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  124. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  125. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  126. #endif
  127. }
  128. else
  129. {
  130. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  131. }
  132. }];
  133. }];
  134. }];
  135. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  136. //
  137. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  138. //
  139. // dispatch_async(dispatch_get_main_queue(), ^{
  140. //
  141. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  142. //
  143. // if([[cart_json valueForKey:@"result"] intValue]==2)
  144. // {
  145. //
  146. // [self end_edit];
  147. //
  148. //
  149. //
  150. //#ifdef RA_NOTIFICATION
  151. // [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  152. //#else
  153. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  154. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  155. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  156. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  157. //#endif
  158. // }
  159. // else
  160. // {
  161. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  162. // }
  163. //
  164. //
  165. //
  166. // });
  167. // });
  168. }];
  169. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  170. DebugLog(@"No");
  171. }];
  172. [alertControl addAction:actionOne];
  173. [alertControl addAction:alertthree];
  174. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  175. [self presentViewController:alertControl animated:YES completion:nil];
  176. DebugLog(@"%@",self.edit_select_arr);
  177. }];
  178. UIAlertAction *actionTwo = [UIAlertAction actionWithTitle:@"Move To Wish List" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  179. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move Models To Wish List" completion:^{
  180. [RANetwork request_move_cart2wish:ids completionHandler:^(NSMutableDictionary *result) {
  181. NSDictionary* cart_json =result;
  182. [waitalert dismissViewControllerAnimated:YES completion:^{
  183. if([[cart_json valueForKey:@"result"] intValue]==2)
  184. {
  185. #ifdef RA_NOTIFICATION
  186. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  187. #else
  188. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  189. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  190. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  191. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  192. #endif
  193. [self end_edit];
  194. }
  195. else
  196. {
  197. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move Models To Wish List" controller:self] ;
  198. }
  199. }];
  200. }];
  201. }];
  202. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  203. //
  204. // NSDictionary* cart_json = [RANetwork move_cart2wish:ids];
  205. //
  206. // dispatch_async(dispatch_get_main_queue(), ^{
  207. //
  208. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  209. //
  210. // if([[cart_json valueForKey:@"result"] intValue]==2)
  211. // {
  212. //
  213. //
  214. //
  215. //
  216. //#ifdef RA_NOTIFICATION
  217. // [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  218. //#else
  219. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  220. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  221. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  222. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  223. //#endif
  224. //
  225. //
  226. // [self end_edit];
  227. // }
  228. // else
  229. // {
  230. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move Models To Wish List" controller:self] ;
  231. // }
  232. //
  233. //
  234. //
  235. // });
  236. // });
  237. }];
  238. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  239. DebugLog(@"No");
  240. }];
  241. [alertControl addAction:actionOne];
  242. [alertControl addAction:actionTwo];
  243. [alertControl addAction:alertthree];
  244. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  245. [self presentViewController:alertControl animated:YES completion:nil];
  246. DebugLog(@"%@",self.edit_select_arr);
  247. }
  248. - (IBAction)onEditAddWishClick:(id)sender {
  249. if(self.edit_select_arr.count==0)
  250. {
  251. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Move To Wish List" controller:self] ;
  252. return;
  253. }
  254. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  255. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  256. // //block代码块取代了delegate
  257. //
  258. //
  259. //
  260. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  261. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move Models To Wish List" completion:^{
  262. [RANetwork request_move_cart2wish:ids completionHandler:^(NSMutableDictionary *result) {
  263. NSDictionary* cart_json = result;
  264. [waitalert dismissViewControllerAnimated:YES completion:^{
  265. if([[cart_json valueForKey:@"result"] intValue]==2)
  266. {
  267. [self end_edit];
  268. #ifdef RA_NOTIFICATION
  269. [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  270. #else
  271. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  272. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  273. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  274. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  275. #endif
  276. }
  277. else
  278. {
  279. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  280. }
  281. }];
  282. }];
  283. }];
  284. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  285. //
  286. // NSDictionary* cart_json = [RANetwork move_cart2wish:ids];
  287. //
  288. // dispatch_async(dispatch_get_main_queue(), ^{
  289. //
  290. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  291. //
  292. // if([[cart_json valueForKey:@"result"] intValue]==2)
  293. // {
  294. //
  295. // [self end_edit];
  296. //
  297. //#ifdef RA_NOTIFICATION
  298. // [ActiveViewController Notify:@"WatchListViewController,CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  299. //#else
  300. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  301. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  302. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  303. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  304. //#endif
  305. //
  306. // }
  307. // else
  308. // {
  309. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  310. // }
  311. //
  312. //
  313. //
  314. // });
  315. // });
  316. // }];
  317. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  318. // DebugLog(@"No");
  319. // }];
  320. // [alertControl addAction:actionOne];
  321. //
  322. // [alertControl addAction:alertthree];
  323. //
  324. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  325. //
  326. //
  327. // [self presentViewController:alertControl animated:YES completion:nil];
  328. //
  329. // DebugLog(@"%@",self.edit_select_arr);
  330. }
  331. - (IBAction)onEditDelClick:(id)sender {
  332. if(self.edit_select_arr.count==0)
  333. {
  334. [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Delete From Cart" controller:self] ;
  335. return;
  336. }
  337. NSString * ids = [self.edit_select_arr componentsJoinedByString:@","];
  338. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Are you sure remove selected models from cart?" message:nil preferredStyle:UIAlertControllerStyleAlert];
  339. //block代码块取代了delegate
  340. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  341. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Models From Cart" completion:^{
  342. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  343. NSMutableDictionary* cart_json =result;
  344. [waitalert dismissViewControllerAnimated:YES completion:^{
  345. if([[cart_json valueForKey:@"result"] intValue]==2)
  346. {
  347. [self end_edit];
  348. #ifdef RA_NOTIFICATION
  349. [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  350. #else
  351. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  352. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  353. [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  354. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  355. #endif
  356. }
  357. else
  358. {
  359. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  360. }
  361. }];
  362. }];
  363. }];
  364. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  365. //
  366. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  367. //
  368. // dispatch_async(dispatch_get_main_queue(), ^{
  369. //
  370. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  371. //
  372. // if([[cart_json valueForKey:@"result"] intValue]==2)
  373. // {
  374. //
  375. // [self end_edit];
  376. //
  377. //
  378. //#ifdef RA_NOTIFICATION
  379. // [ActiveViewController Notify:@"CartViewController,CategoryViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  380. //#else
  381. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  382. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:true];
  383. // [((MainViewController*)appDelegate.main_vc) reloadCategory:true immediately:true];
  384. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  385. //#endif
  386. // }
  387. // else
  388. // {
  389. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  390. // }
  391. //
  392. //
  393. //
  394. // });
  395. // });
  396. }];
  397. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  398. DebugLog(@"No");
  399. }];
  400. [alertControl addAction:actionOne];
  401. [alertControl addAction:alertthree];
  402. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  403. [self presentViewController:alertControl animated:YES completion:nil];
  404. DebugLog(@"%@",self.edit_select_arr);
  405. }
  406. - (IBAction)onEndEditClick:(id)sender {
  407. [self end_edit];
  408. }
  409. -(void)begin_edit
  410. {
  411. self.toolpanel.hidden = true;
  412. self.toolbar.hidden = false;
  413. // DebugLog(@"begin edit %@",NSStringFromCGRect(self.cartItemView.frame));
  414. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  415. if ( UIInterfaceOrientationIsPortrait(orientation))
  416. self.cartItemView.frame = CGRectMake(0,40,768,840);
  417. else
  418. self.cartItemView.frame = CGRectMake(0,40,1024,584);
  419. [self.itemListTable setEditing:true animated:YES];
  420. [self.itemListTable reloadData];
  421. }
  422. -(void) end_edit
  423. {
  424. self.toolpanel.hidden=false;
  425. self.toolbar.hidden=true;
  426. // DebugLog(@"end edit %@",NSStringFromCGRect(self.cartItemView.frame));
  427. UIInterfaceOrientation orientation = [[UIApplication sharedApplication]statusBarOrientation];
  428. if ( UIInterfaceOrientationIsPortrait(orientation))
  429. self.cartItemView.frame = CGRectMake(0,40,768,760);
  430. else
  431. self.cartItemView.frame = CGRectMake(0,40,1024,508);
  432. [self.itemListTable setEditing:false animated:YES];
  433. [self.edit_select_arr removeAllObjects];
  434. [self.itemListTable reloadData];
  435. // [self reload_data];
  436. }
  437. - (IBAction)onEditClick:(id)sender {
  438. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  439. //
  440. // [appDelegate test_onDecodedDataResult:@"4400022"];
  441. //
  442. //
  443. // return;
  444. [self begin_edit];
  445. }
  446. #ifndef RA_NOTIFICATION
  447. -(void) reload_container_getdata:(bool) update_data
  448. {
  449. [super reload_container_getdata:update_data];
  450. if(update_data)
  451. [self reload_data];
  452. else
  453. {
  454. [self.itemListTable reloadData];
  455. [self refresh_total];
  456. }
  457. }
  458. #endif
  459. -(void) showHidePrice
  460. {
  461. #ifndef RA_NOTIFICATION
  462. [self reload_container_getdata:false];
  463. #endif
  464. // [self refresh_total];
  465. }
  466. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  467. {
  468. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  469. if (self) {
  470. // Custom initialization
  471. }
  472. return self;
  473. }
  474. - (IBAction)imgbtnClick:(UIButton *)sender {
  475. #ifdef SCANNER_ORDER
  476. return;
  477. #endif
  478. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  479. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  480. // DebugLog(@"shouldchangeedit %d_%d",indexPath.section,indexPath.row);
  481. NSDictionary * item_json = nil;
  482. if (self.back_order_flag) {
  483. item_json = [self itemJsonAtIndexPath:indexPath];
  484. } else {
  485. item_json = self.content_arr[indexPath.row];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  486. }
  487. NSString* product_id = [item_json valueForKey:@"product_id"];
  488. NSString *name = [item_json valueForKey:@"model"];
  489. int is_rate = [item_json[@"is_rate"] intValue];
  490. if(is_rate==1)
  491. return;
  492. DetailViewController* dvc = [[UIStoryboard storyboardWithName:@"ERP_Mobile_Model" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController" ];
  493. // dvc
  494. dvc.product_id=product_id;
  495. dvc.category_id=nil;
  496. dvc.ispush=true;
  497. dvc.model_name = name;
  498. [dvc reload];
  499. [self.navigationController pushViewController:dvc animated:true];
  500. }
  501. -(void)viewWillLayoutSubviews
  502. {
  503. // if(self.showDetail==true)
  504. // {
  505. // UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  506. // int width=175;
  507. // // int height;
  508. // if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight)
  509. // {
  510. // width = 370;
  511. // // height = 400;
  512. // }
  513. // else
  514. // {
  515. // // height = 300;
  516. // width = 175;
  517. // }
  518. //
  519. //
  520. // CGRect frame = CGRectMake(0, 64, width, self.view.bounds.size.height-64);
  521. //
  522. // self.collectionview.frame=frame;
  523. //
  524. //
  525. //
  526. // CGRect framedetail = CGRectMake(width,64 ,self.view.bounds.size.width-width,self.view.bounds.size.height-64);
  527. // self.detailView.frame = framedetail;
  528. // }
  529. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  530. // self.collectionview.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.collectionview.bounds].CGPath;
  531. }
  532. - (void)viewWillAppear:(BOOL)animated
  533. {
  534. [super viewWillAppear:animated];
  535. // print 13 email 19 cancel 24 place order
  536. // Shop 权限检查
  537. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  538. if (appDelegate.user && appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  539. if (![RASingleton sharedInstance].permissions_edit_order) {
  540. CGRect frame0 = self.cancelOrderButton.frame;
  541. CGRect frame1 = self.placeOrderButton.frame;
  542. CGRect frame2 = self.emailButton.frame;
  543. CGRect frame3 = self.printButton.frame;
  544. CGFloat x = CGRectGetMaxX(frame1) - frame0.size.width;
  545. frame0.origin.x = x;
  546. self.cancelOrderButton.frame = frame0;
  547. x -= 20 + CGRectGetWidth(frame2);
  548. frame2.origin.x = x;
  549. self.emailButton.frame = frame2;
  550. x -= 20 + CGRectGetWidth(frame3);
  551. frame3.origin.x = x;
  552. self.printButton.frame = frame3;
  553. self.placeOrderButton.hidden = YES;
  554. } else {
  555. self.placeOrderButton.hidden = NO;
  556. CGSize size = cancelButtonFrame.size;
  557. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  558. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  559. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  560. CGRect frame2 = self.emailButton.frame;
  561. x -= 20 + CGRectGetWidth(frame2);
  562. frame2.origin.x = x;
  563. self.emailButton.frame = frame2;
  564. CGRect frame3 = self.printButton.frame;
  565. x -= 20 + CGRectGetWidth(frame3);
  566. frame3.origin.x = x;
  567. self.printButton.frame = frame3;
  568. }
  569. } else {
  570. // self.cancelOrderButton.frame = cancelButtonFrame;
  571. self.placeOrderButton.hidden = NO;
  572. CGSize size = cancelButtonFrame.size;
  573. CGFloat x = CGRectGetMinX(self.placeOrderButton.frame) - 24 - size.width;
  574. CGFloat y = CGRectGetMinY(self.placeOrderButton.frame);
  575. self.cancelOrderButton.frame = CGRectMake(x, y, size.width, size.height);
  576. CGRect frame2 = self.emailButton.frame;
  577. x -= 20 + CGRectGetWidth(frame2);
  578. frame2.origin.x = x;
  579. self.emailButton.frame = frame2;
  580. CGRect frame3 = self.printButton.frame;
  581. x -= 20 + CGRectGetWidth(frame3);
  582. frame3.origin.x = x;
  583. self.printButton.frame = frame3;
  584. }
  585. #ifdef OFFLINE_MODE
  586. // 离线隐藏Email
  587. self.emailButton.hidden = appDelegate.offline_mode;
  588. // 离线隐藏Print
  589. self.printButton.hidden = appDelegate.offline_mode;
  590. #endif
  591. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  592. #ifdef SCANNER_ORDER
  593. if(appDelegate.user_type == USER_ROLE_EMPLOYEE)
  594. {
  595. self.btnBulkDiscount.hidden = false;
  596. }
  597. else
  598. self.btnBulkDiscount.hidden = true;
  599. #endif
  600. }
  601. - (void)checkProductAvailable:(NSArray *)contents {
  602. if (contents == nil) {
  603. self.available = NO;
  604. return;
  605. }
  606. [contents enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  607. if ([obj isKindOfClass:[NSDictionary class]]) {
  608. NSDictionary *item_json = (NSDictionary *)obj;
  609. BOOL isAvailable = ![[item_json valueForKey:@"is_out_of_stock"] boolValue];
  610. self.available = self.available && isAvailable;
  611. }
  612. }];
  613. }
  614. - (void)clearContent {
  615. dispatch_async(dispatch_get_main_queue(), ^{
  616. self.freejson = nil;
  617. self.notes = nil;
  618. self.content_arr = nil;
  619. self.currentOrderIsMerged = nil;
  620. self.cart_json = nil;
  621. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  622. self.print_url = nil;
  623. [self checkProductAvailable:self.content_arr];
  624. [self refresh_total];
  625. [self.itemListTable reloadData];
  626. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  627. appDelegate.cart_count = 0;
  628. [appDelegate update_count_mark];
  629. });
  630. }
  631. -(void) operation_reload_data
  632. {
  633. if (self.dataOperationQueue.operationCount > 1) {
  634. return;
  635. }
  636. __block AppDelegate *appDelegate = nil;
  637. dispatch_sync(dispatch_get_main_queue(), ^{
  638. //some UI methods ej
  639. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  640. });
  641. // AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  642. #ifndef SCANNER_ORDER
  643. //扫码订单允许后建订单
  644. if (appDelegate.order_code == nil || appDelegate.order_code.length == 0) {
  645. [self clearContent];
  646. return;
  647. }
  648. #endif
  649. __weak typeof(self) weakself = self;
  650. dispatch_async(dispatch_get_main_queue(), ^{
  651. if(weakself.isrefreshing)
  652. return;
  653. weakself.available = YES;
  654. weakself.itemListTable.hidden = true;
  655. weakself.label_net_err.hidden=true;
  656. weakself.isrefreshing=true;
  657. // [self.content_data removeAllObjects];
  658. // [self.itemListTable reloadData];
  659. // UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  660. //
  661. // [reF endRefreshing];
  662. //
  663. // reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  664. weakself.mum.center = weakself.view.center;
  665. weakself.mum.hidden = YES;
  666. // [self.mum startAnimating];
  667. DebugLog(@"reloading...");
  668. __block UIAlertController *loadingView = [RAUtils waiting_alert:self title:@"Loading" completion:^{
  669. [RANetwork request_cart:weakself.sortIndex completionHandler:^(NSMutableDictionary *result) {
  670. DebugLog(@"BEGIN LOAD CART");
  671. NSDictionary* cart_json = result;
  672. //
  673. // [self.mum stopAnimating];
  674. [loadingView dismissViewControllerAnimated:YES completion:^{
  675. // [loadingView dismissWithClickedButtonIndex:0 animated:YES];
  676. // self.content_data = [cart_json mutableCopy];
  677. #ifdef BACKORDER_PROCESS
  678. weakself.back_order_flag = [[cart_json objectForKey:@"back_order_version"] boolValue];
  679. #else
  680. weakself.back_order_flag = NO;
  681. #endif
  682. if (!weakself.back_order_flag) {
  683. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  684. weakself.notes = [cart_json valueForKey:@"general_note"];
  685. weakself.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  686. weakself.currentOrderIsMerged = [[cart_json valueForKey:@"is_merged_order"] boolValue];
  687. [RASingleton sharedInstance].currentOrderIsMerged = weakself.currentOrderIsMerged;
  688. [weakself.itemListTable reloadData];
  689. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  690. [weakself checkProductAvailable:weakself.content_arr];
  691. [weakself refresh_total];
  692. } else {
  693. // v1.94
  694. weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  695. weakself.notes = [cart_json valueForKey:@"general_note"];
  696. weakself.cart_json = cart_json;
  697. [weakself.itemListTable reloadData];
  698. weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  699. [weakself checkProductAvailable:weakself.content_arr];
  700. }
  701. int result_code=[[cart_json valueForKey:@"result"] intValue];
  702. if (weakself.dataOperationQueue.operationCount > 1) {
  703. weakself.isrefreshing=false;
  704. return;
  705. }
  706. if(result_code==2||result_code==1||result_code==0)
  707. {
  708. [weakself.edit_select_arr removeAllObjects];
  709. weakself.itemListTable.hidden = false;
  710. // UIApplication * app = [UIApplication sharedApplication];
  711. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  712. // appDelegate.cart_count =weakself.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  713. weakself.itemListTable.hidden=false;
  714. if(weakself.onFinishLoad)
  715. weakself.onFinishLoad();
  716. }
  717. else
  718. if(result_code==RESULT_NET_ERROR)
  719. {
  720. weakself.label_net_err.hidden=false;
  721. weakself.itemListTable.hidden=true;
  722. }
  723. else
  724. {
  725. if(result_code!=1)
  726. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Cart" controller:weakself] ;
  727. }
  728. weakself.isrefreshing=false;
  729. DebugLog(@"FINISH LOAD CART");
  730. }];
  731. }];
  732. }];
  733. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  734. // DebugLog(@"BEGIN LOAD CART");
  735. // NSDictionary* cart_json = [RANetwork request_Cart:weakself.sortIndex];
  736. //
  737. // dispatch_async(dispatch_get_main_queue(), ^{
  738. // //
  739. //// [self.mum stopAnimating];
  740. // [loadingView dismissWithClickedButtonIndex:0 animated:YES];
  741. //
  742. // // self.content_data = [cart_json mutableCopy];
  743. //#ifdef BACKORDER_PROCESS
  744. // weakself.back_order_flag = [[cart_json objectForKey:@"back_order_version"] boolValue];
  745. //#else
  746. // weakself.back_order_flag = NO;
  747. //#endif
  748. //
  749. // if (!weakself.back_order_flag) {
  750. // weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  751. // weakself.notes = [cart_json valueForKey:@"general_note"];
  752. // weakself.content_arr = [RAUtils dictionary2array:cart_json count_fields:@"count" item_mark:@"item_" items_mark:nil];
  753. // weakself.currentOrderIsMerged = [[cart_json valueForKey:@"is_merged_order"] boolValue];
  754. // [Singleton sharedInstance].currentOrderIsMerged = weakself.currentOrderIsMerged;
  755. // [weakself.itemListTable reloadData];
  756. // weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  757. //
  758. //
  759. // [weakself checkProductAvailable:weakself.content_arr];
  760. //
  761. //
  762. // [weakself refresh_total];
  763. // } else {
  764. // // v1.94
  765. // weakself.freejson = [cart_json objectForKey:@"freeGiveaway"];
  766. // weakself.notes = [cart_json valueForKey:@"general_note"];
  767. // weakself.cart_json = cart_json;
  768. // [weakself.itemListTable reloadData];
  769. // weakself.print_url = [cart_json valueForKey:@"cart_print_url"];
  770. // [weakself checkProductAvailable:weakself.content_arr];
  771. // }
  772. //
  773. // int result=[[cart_json valueForKey:@"result"] intValue];
  774. //
  775. // if (weakself.dataOperationQueue.operationCount > 1) {
  776. // weakself.isrefreshing=false;
  777. // return;
  778. // }
  779. //
  780. // if(result==2||result==1||result==0)
  781. // {
  782. //
  783. // [weakself.edit_select_arr removeAllObjects];
  784. //
  785. // weakself.itemListTable.hidden = false;
  786. //// UIApplication * app = [UIApplication sharedApplication];
  787. //// AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  788. //// appDelegate.cart_count =weakself.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  789. // weakself.itemListTable.hidden=false;
  790. // if(weakself.onFinishLoad)
  791. // weakself.onFinishLoad();
  792. // }
  793. // else
  794. // if(result==RESULT_NET_ERROR)
  795. // {
  796. // weakself.label_net_err.hidden=false;
  797. // weakself.itemListTable.hidden=true;
  798. // }
  799. // else
  800. // {
  801. // if(result!=1)
  802. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Loading Cart" controller:weakself] ;
  803. // }
  804. //
  805. // weakself.isrefreshing=false;
  806. // DebugLog(@"FINISH LOAD CART");
  807. //
  808. // });
  809. // });
  810. });
  811. // [[self navigationController] setNavigationBarHidden:YES animated:NO];
  812. }
  813. -(void)manually_refresh
  814. {
  815. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  816. if(self.isrefreshing)
  817. {
  818. [reF endRefreshing];
  819. return;
  820. }
  821. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Refreshing"];
  822. [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
  823. // DebugLog(@"refresh!!!!!!!!");
  824. }
  825. -(void) ReloadData
  826. {
  827. UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
  828. [reF endRefreshing];
  829. reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  830. [self reload_data];
  831. }
  832. - (void)viewDidLayoutSubviews {
  833. [super viewDidLayoutSubviews];
  834. [self layoutCartIndicatorBar];
  835. }
  836. - (DefaultTableHeaderView *)setupCartIndicatorBar {
  837. NSString* value =[DefaultAppearance get_noneappearance_value:@"DefaultTableHeaderView" valuename:@"title_text_color"];
  838. if(value==nil)
  839. value=@"";
  840. unsigned long color = strtoul([value UTF8String],0,16);
  841. DefaultTableHeaderView* myView = [[DefaultTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
  842. // myView.backgroundColor = UIColorFromRGB(0x996633);
  843. myView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  844. myView.layer.shadowPath =[UIBezierPath bezierPathWithRect:myView.bounds].CGPath;
  845. myView.layer.shadowColor = [UIColor blackColor].CGColor;
  846. myView.layer.shadowOffset = CGSizeMake(0, 0);
  847. myView.layer.shadowOpacity = 0.5;
  848. myView.layer.shadowRadius = 2.0;
  849. #ifndef SCANNER_ORDER
  850. self.sortButton.tag = 5678 + 0;
  851. [myView addSubview:self.sortButton];
  852. #endif
  853. UILabel *solabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 9, 90, 22)];
  854. solabel.tag = 5678 + 1;
  855. solabel.textColor=UIColorFromRGB(color);
  856. solabel.backgroundColor = [UIColor clearColor];
  857. solabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  858. solabel.text=NSLocalizedString(@"Description", nil);
  859. [solabel sizeToFit];
  860. [myView addSubview:solabel];
  861. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  862. UILabel *contactlabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  863. contactlabel.tag = 5678 + 2;
  864. contactlabel.textColor=UIColorFromRGB(color);
  865. contactlabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  866. contactlabel.backgroundColor = [UIColor clearColor];
  867. #ifdef SCANNER_ORDER
  868. NSString* pricename;
  869. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  870. NSString* servername = [addressDic objectForKey:@"show_name"];
  871. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  872. NSString * shortname = arrsn[0];
  873. if(shortname.length==0)
  874. shortname = servername;
  875. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  876. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  877. // self.labelPrice0.text = price_group[@"price_0"][@"display"];//appDelegate.price0_name;
  878. // self.labelPrice1.text = price_group[@"price_1"][@"display"];//appDelegate.price1_name;
  879. switch(RASingleton.sharedInstance.price_type)
  880. {
  881. case 0:
  882. // pricename =[NSString stringWithFormat:@"%@_DDP",shortname];
  883. pricename = price_group[@"price_0"][@"display"];
  884. break;;
  885. case 1:
  886. // pricename = [NSString stringWithFormat:@"%@_WHSE",shortname];;
  887. pricename=price_group[@"price_1"][@"display"];//@"WHSE";
  888. break;;
  889. // case 2: pricename = @"25%";
  890. // break;
  891. }
  892. contactlabel.text=pricename;
  893. // contactlabel.frame= CGRectMake(x-100, 9, 90, 22);
  894. // contactlabel.tran
  895. #else
  896. contactlabel.text=NSLocalizedString(@"Unit price", nil);
  897. #endif
  898. [contactlabel sizeToFit];
  899. [myView addSubview:contactlabel];
  900. x = self.itemListTable.bounds.size.width - (768 - 470);
  901. UILabel *modellabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  902. modellabel.tag = 5678 + 3;
  903. modellabel.textColor=UIColorFromRGB(color);
  904. modellabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  905. modellabel.backgroundColor = [UIColor clearColor];
  906. modellabel.text=NSLocalizedString(@"Discount/QTY", nil);
  907. [modellabel sizeToFit];
  908. [myView addSubview:modellabel];
  909. x = self.itemListTable.bounds.size.width - (768 - 640);
  910. UILabel *pricelabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 9, 90, 22)];
  911. pricelabel.tag = 5678 + 4;
  912. pricelabel.textColor=UIColorFromRGB(color);
  913. pricelabel.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin;
  914. pricelabel.backgroundColor = [UIColor clearColor];
  915. pricelabel.text=NSLocalizedString(@"Set/Subtotal", nil);
  916. [pricelabel sizeToFit];
  917. [myView addSubview:pricelabel];
  918. return myView;
  919. }
  920. - (void)layoutCartIndicatorBar {
  921. CGFloat x = self.itemListTable.bounds.size.width - (768 - 320);
  922. UILabel *solabel = [self.cartIndicatorBar viewWithTag:5678 + 1];
  923. [solabel sizeToFit];
  924. UILabel *contactlabel = [self.cartIndicatorBar viewWithTag:5678 + 2];
  925. contactlabel.frame = CGRectMake(x, 9, 90, 22);
  926. [contactlabel sizeToFit];
  927. x = self.itemListTable.bounds.size.width - (768 - 470);
  928. UILabel *modellabel = [self.cartIndicatorBar viewWithTag:5678 + 3];
  929. modellabel.frame = CGRectMake(x, 9, 90, 22);
  930. [modellabel sizeToFit];
  931. x = self.itemListTable.bounds.size.width - (768 - 640);
  932. UILabel *pricelabel = [self.cartIndicatorBar viewWithTag:5678 + 4];
  933. pricelabel.frame = CGRectMake(x, 9, 90, 22);
  934. [pricelabel sizeToFit];
  935. }
  936. - (void)viewDidLoad
  937. {
  938. [super viewDidLoad];
  939. #ifdef BUILD_CONTRAST
  940. self.btnOrderDiscount.hidden=false;
  941. #endif
  942. #ifdef SCANNER_ORDER
  943. self.printButton.hidden = true;
  944. self.emailButton.hidden = true;
  945. self.editButton.hidden = true;
  946. self.continueButton.hidden = true;
  947. self.labelTotalcuft.hidden = false;
  948. self.labelTotalWeight.hidden = true;
  949. self.labelTotalCarton.hidden = true;
  950. self.valuecuft.hidden = false;
  951. self.valueweight.hidden = true;
  952. self.valuecarton.hidden = true;
  953. #endif
  954. #ifdef RA_NOTIFICATION
  955. self.support_scanner = true;
  956. #endif
  957. self.edit_select_arr= [[NSMutableArray alloc] init];
  958. self.label_net_err.layer.borderColor = [UIColor darkGrayColor].CGColor;
  959. self.label_net_err.layer.borderWidth = 2.0;
  960. self.label_net_err.layer.cornerRadius=15;
  961. self.label_net_err.layer.masksToBounds=true;
  962. #ifdef SCANNER_ORDER
  963. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cartrefresh:) name:@"RA_NOTIFICATION_CART_REFRESH" object:nil];
  964. #endif
  965. #ifndef RA_NOTIFICATION
  966. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(priceTypeChanged:) name:Change_Price_Type_Notification object:nil];
  967. #endif
  968. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refresh_btn_click:)];
  969. // tap.minimumPressDuration = 0.8; //定义按的时间
  970. [self.label_net_err addGestureRecognizer:tap];
  971. UIRefreshControl *ref = [[UIRefreshControl alloc]init];
  972. ref.tag = 200 ;
  973. ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"Pull to refresh"];
  974. ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  975. // ref.hidden = true;
  976. [ref addTarget:self action:@selector(manually_refresh) forControlEvents:UIControlEventValueChanged];
  977. [self.itemListTable addSubview:ref];
  978. self.sortIndex = 0;
  979. self.currentOrderIsMerged = NO;
  980. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  981. self.toolpanel.layer.masksToBounds = false;
  982. //添加四个边阴影
  983. self.toolpanel.layer.shadowColor = [UIColor blackColor].CGColor;
  984. self.toolpanel.layer.shadowOffset = CGSizeMake(0, 0);
  985. self.toolpanel.layer.shadowOpacity = 0.5;
  986. self.toolpanel.layer.shadowRadius = 2.0;
  987. cancelButtonFrame = self.cancelOrderButton.frame;
  988. // CGRect frame =self.orderInfoTableView.tableHeaderView.frame;
  989. // self.orderInfoTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.orderInfoTableView.bounds.size.width, 0.0001)];
  990. // self.orderInfoTableView.tableHeaderView.backgroundColor = [UIColor redColor];
  991. // // self.detailTable.sectionHeaderHeight = 0.0001;
  992. // self.orderInfoTableView.sectionFooterHeight = 0.0001;
  993. // Do any additional setup after loading the view.
  994. self.cartIndicatorBar = [self setupCartIndicatorBar];
  995. [self.view addSubview:self.cartIndicatorBar];
  996. }
  997. -(void) cartrefresh: (NSNotification *)notification
  998. {
  999. [OLDataProvider scanRefreshCart];
  1000. [ActiveViewController Notify:@"CartViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1001. // [self refresh_total];
  1002. // [self refresh_ui];
  1003. }
  1004. //-(void)SelectOrder:(NSString *)orderid
  1005. //{
  1006. //// self.editOrderID.text=orderid;
  1007. //// self.btnAddToOrder.enabled = true;
  1008. //}
  1009. - (void)didReceiveMemoryWarning
  1010. {
  1011. [super didReceiveMemoryWarning];
  1012. // Dispose of any resources that can be recreated.
  1013. }
  1014. //- (IBAction)stepperAction:(UIStepper *)sender {
  1015. //
  1016. //
  1017. //}
  1018. - (IBAction)onContinueShoppingClick:(id)sender {
  1019. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1020. [appDelegate switchToPreviousVC];
  1021. }
  1022. - (IBAction)onOrderDiscount:(id)sender {
  1023. #ifdef BUILD_CONTRAST
  1024. OrderDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"OrderDiscountViewController"];
  1025. // vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  1026. // vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  1027. // vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1028. // __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1029. // vc.delegate = parentvc.self;
  1030. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1031. vc.onSetValue = ^(double discount){
  1032. // bool bmodify=false;
  1033. // if(discount>0)
  1034. // bmodify=true;
  1035. // NSString* notes = [item_json valueForKey:@"note"];
  1036. // if(notes.length==0)
  1037. // notes=@"";
  1038. // if(bmodify)
  1039. // {
  1040. //
  1041. //
  1042. // // if([notes isEqualToString:@""])
  1043. //// notes=[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  1044. ////
  1045. //// NSRange range;
  1046. //// range = [notes rangeOfString:@"PRICE MODIFIED"];
  1047. //// if (range.location != NSNotFound) {
  1048. ////
  1049. //// }else{
  1050. //// notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  1051. //// }
  1052. // }
  1053. // else
  1054. //
  1055. // {
  1056. //// notes =@"";
  1057. // }
  1058. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Discount" completion:^{
  1059. [RANetwork request_order_discount:discount completionHandler:^(NSMutableDictionary *result) {
  1060. [waitalert dismissViewControllerAnimated:YES completion:^{
  1061. int iresult = [result[@"result"] intValue];
  1062. if(iresult==RESULT_TRUE)
  1063. {
  1064. [self reload_data];
  1065. }
  1066. else
  1067. {
  1068. [RAUtils message_alert:@"Can't set order discount, please contact administrator" title:@"Set Order Discount" controller:self];
  1069. }
  1070. // if([[cart_json valueForKey:@"result"] intValue]==2)
  1071. // {
  1072. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1073. //
  1074. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1075. // // [item_json setValue:notes forKey:@"note"];
  1076. //
  1077. // // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1078. // // if (self.back_order_flag) {
  1079. // // [self updateItemJson:item_json atIndexPath:indexPath];
  1080. // // } else {
  1081. // // self.content_arr[indexPath.row ] = item_json;
  1082. // // }
  1083. // // tableView.editing = false;
  1084. // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1085. // // [self refresh_total];
  1086. //
  1087. //
  1088. // [self reload_data];
  1089. //
  1090. // #ifdef RA_NOTIFICATION
  1091. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1092. // #else
  1093. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1094. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1095. // #endif
  1096. // }
  1097. // else
  1098. // {
  1099. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1100. // }
  1101. }];
  1102. }];
  1103. // [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1104. // NSDictionary* cart_json = result;
  1105. //
  1106. // [waitalert dismissViewControllerAnimated:YES completion:^{
  1107. // if([[cart_json valueForKey:@"result"] intValue]==2)
  1108. // {
  1109. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1110. //
  1111. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1112. //// [item_json setValue:notes forKey:@"note"];
  1113. //
  1114. //// RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1115. //// if (self.back_order_flag) {
  1116. //// [self updateItemJson:item_json atIndexPath:indexPath];
  1117. //// } else {
  1118. //// self.content_arr[indexPath.row ] = item_json;
  1119. //// }
  1120. //// tableView.editing = false;
  1121. // // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1122. // // [self refresh_total];
  1123. //
  1124. //
  1125. // [self reload_data];
  1126. //
  1127. // #ifdef RA_NOTIFICATION
  1128. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1129. // #else
  1130. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1131. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1132. // #endif
  1133. // }
  1134. // else
  1135. // {
  1136. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1137. // }
  1138. // }];
  1139. //
  1140. //
  1141. //
  1142. //
  1143. //
  1144. //
  1145. // }];
  1146. }];
  1147. };
  1148. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1149. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1150. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1151. [self presentViewController:navi animated:YES completion:^{
  1152. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1153. DebugLog(@"EditModelPriceViewController present.........");
  1154. // self.btop = false;
  1155. // <#code#>
  1156. }];
  1157. #endif
  1158. }
  1159. - (IBAction)onPlaceOrder:(UIButton *)sender {
  1160. #ifndef SCANNER_ORDER
  1161. if (![self isOrderAvailable]) {
  1162. return;
  1163. }
  1164. #endif
  1165. [self placeOrder];
  1166. }
  1167. -(void) scanPlaceOrder
  1168. {
  1169. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1170. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1171. // NSString * string = [checked componentsJoinedByString:@","];
  1172. // [params setValue:string forKey:@"cart2Checkbox"];
  1173. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1174. // NSError *error=nil;
  1175. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1176. //
  1177. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1178. // NSString *documents = [paths objectAtIndex:0];
  1179. NSString *orderdir = [OLDataProvider getScanPath];
  1180. NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1181. int section_count = [dict[@"section_count"] intValue];
  1182. for(int i=0;i<section_count;i++)
  1183. {
  1184. NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1185. NSString* title = section[@"title"];
  1186. if([title isEqualToString:@"Model Information"])
  1187. {
  1188. NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1189. int cart_count = [cart_section[@"count"] intValue];
  1190. for(int j=0;j<cart_count;j++)
  1191. {
  1192. NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1193. cart_item[@"description"]= [NSString stringWithFormat:@"%@\n%@\n%@",cart_item[@"model"],cart_item[@"description"],cart_item[@"dimension"] ];
  1194. cart_item[@"control"]=@"model";
  1195. section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1196. }
  1197. section[@"count"] = @(cart_count);
  1198. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1199. }
  1200. else
  1201. if([title isEqualToString:@"Customer"])
  1202. {
  1203. int scount = [section[@"count"] intValue];
  1204. for(int j=0;j<scount;j++)
  1205. {
  1206. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1207. NSString * name = item[@"name"];
  1208. if([name isEqualToString:@"business_card"])
  1209. {
  1210. NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1211. for(int l=0;l<arr.count;l++)
  1212. {
  1213. item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1214. }
  1215. }
  1216. else
  1217. {
  1218. if(item[@"value"]==nil ||[item[@"value"] stringValue].length==0) //order 内没有值才从customer 复制
  1219. item[@"value"]=appDelegate.customerInfo[name];
  1220. }
  1221. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1222. }
  1223. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1224. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1225. }
  1226. else
  1227. if([title isEqualToString:@"Remarks Content"])
  1228. {
  1229. int scount = [section[@"count"] intValue];
  1230. for(int j=0;j<scount;j++)
  1231. {
  1232. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1233. NSString * name = item[@"name"];
  1234. if([name isEqualToString:@"comments"])
  1235. {
  1236. item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1237. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1238. }
  1239. }
  1240. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1241. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1242. }
  1243. else if([title isEqualToString:@"Order Total"])
  1244. {
  1245. int scount = [section[@"count"] intValue];
  1246. for(int j=0;j<scount;j++)
  1247. {
  1248. NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1249. NSString * name = item[@"name"];
  1250. if([name isEqualToString:@"totalPrice"])
  1251. {
  1252. item[@"value"] = [RAConvertor currencyNumber:self.total+self.surcharge];//[NSString stringWithFormat:@"%.2f",self.total+self.surcharge];
  1253. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1254. }
  1255. else if([name isEqualToString:@"subtotalPrice"])
  1256. {
  1257. item[@"value"] = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"%.2f",self.total];
  1258. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1259. }
  1260. else if([name isEqualToString:@"surcharge"])
  1261. {
  1262. item[@"value"] = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"%.2f",self.surcharge];
  1263. section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1264. }
  1265. }
  1266. // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1267. dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1268. }
  1269. }
  1270. // NSString *path = NSTemporaryDirectory();
  1271. //
  1272. // NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  1273. // NSString *filePath = [path stringByAppendingPathComponent:file];
  1274. //
  1275. //
  1276. //
  1277. [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  1278. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1279. orderinfoVC.disable_dropdown_refresh=true;
  1280. orderinfoVC.url_type = URL_FILE;
  1281. orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  1282. orderinfoVC.params = params;
  1283. orderinfoVC.title=@"";
  1284. orderinfoVC.delegate=self;
  1285. //
  1286. // if(checked.count==count)
  1287. // {
  1288. // orderinfoVC.have_tail = true
  1289. // }
  1290. [self.navigationController pushViewController:orderinfoVC animated:true];
  1291. return;
  1292. }
  1293. - (IBAction)onBulkDiscount:(id)sender {
  1294. #ifdef SCANNER_ORDER
  1295. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  1296. vc.bulk = true;
  1297. vc.discount=0;
  1298. // vc.price = 0;
  1299. // vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  1300. // __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  1301. // vc.delegate = parentvc.self;
  1302. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1303. vc.onSetValue = ^(double price,double discount){
  1304. bool bmodify=false;
  1305. if(discount>0)
  1306. bmodify=true;
  1307. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  1308. [RANetwork request_scan_bulkdiscount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  1309. NSDictionary* cart_json = result;
  1310. [waitalert dismissViewControllerAnimated:YES completion:^{
  1311. if([[cart_json valueForKey:@"result"] intValue]==2)
  1312. {
  1313. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  1314. //
  1315. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  1316. // [item_json setValue:notes forKey:@"note"];
  1317. // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  1318. // if (self.back_order_flag) {
  1319. // [self updateItemJson:item_json atIndexPath:indexPath];
  1320. // } else {
  1321. // self.content_arr[indexPath.row ] = item_json;
  1322. // }
  1323. // tableView.editing = false;
  1324. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  1325. // [self refresh_total];
  1326. [self reload_data];
  1327. #ifdef RA_NOTIFICATION
  1328. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  1329. #else
  1330. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1331. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  1332. #endif
  1333. }
  1334. else
  1335. {
  1336. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  1337. }
  1338. }];
  1339. }];
  1340. }];
  1341. };
  1342. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  1343. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1344. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1345. [self presentViewController:navi animated:YES completion:^{
  1346. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1347. DebugLog(@"EditModelPriceViewController present.........");
  1348. // self.btop = false;
  1349. // <#code#>
  1350. }];
  1351. #endif
  1352. }
  1353. - (IBAction)onChangePrice:(id)sender {
  1354. #ifdef SCANNER_ORDER
  1355. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1356. if(RASingleton.sharedInstance.scan_cart ==nil)
  1357. {
  1358. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1359. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1360. RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1361. }
  1362. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  1363. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Change Price Type" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1364. UIAlertAction *action1 = [UIAlertAction actionWithTitle:price_group[@"price_0"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1365. // self.btnPrice.titleLabel.text = @"FOB CTNR";
  1366. [self.btnPrice setTitle: price_group[@"price_0"][@"display"] forState:UIControlStateNormal];
  1367. RASingleton.sharedInstance.price_type=0;
  1368. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1369. int count = [section[@"count"] intValue];
  1370. for(int i=0;i<count;i++)
  1371. {
  1372. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1373. item[@"price"]= item[@"price0"];
  1374. item[@"unit_price"]= item[@"price0"];
  1375. item[@"erp_unit_price"]= item[@"price0"];
  1376. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1377. }
  1378. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1379. RASingleton.sharedInstance.scan_cart[@"price_type"] = @0;
  1380. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1381. [self.cartIndicatorBar removeFromSuperview];
  1382. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1383. [self.view addSubview:self.cartIndicatorBar];
  1384. [self reload_data];
  1385. }];
  1386. UIAlertAction *action2 = [UIAlertAction actionWithTitle:price_group[@"price_1"][@"display"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1387. [self.btnPrice setTitle: price_group[@"price_1"][@"display"] forState:UIControlStateNormal];
  1388. RASingleton.sharedInstance.price_type=1;
  1389. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1390. int count = [section[@"count"] intValue];
  1391. for(int i=0;i<count;i++)
  1392. {
  1393. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1394. NSString * unit_price;
  1395. if(item [@"net_price"])
  1396. unit_price=item[@"price3"];
  1397. else if(item [@"special_price"])
  1398. {
  1399. unit_price= item[@"price2"];
  1400. }
  1401. else
  1402. {
  1403. unit_price= item[@"price1"];
  1404. }
  1405. if([unit_price isEqualToString:@"N/A"])
  1406. unit_price = @"0";
  1407. else
  1408. {
  1409. unit_price = [NSString stringWithFormat:@"%.2f", [unit_price doubleValue]];
  1410. }
  1411. item[@"unit_price"] = unit_price;
  1412. item[@"erp_unit_price"] = unit_price;
  1413. item[@"price"]= unit_price;//item[@"price1"];
  1414. // item[@"unit_price"]= item[@"price1"];
  1415. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1416. }
  1417. RASingleton.sharedInstance.scan_cart[@"price_type"] = @1;
  1418. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1419. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1420. [self.cartIndicatorBar removeFromSuperview];
  1421. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1422. [self.view addSubview:self.cartIndicatorBar];
  1423. [self reload_data];
  1424. }];
  1425. UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"%25" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1426. // self.btnPrice.titleLabel.text = @"%25";
  1427. [self.btnPrice setTitle: @"%25" forState:UIControlStateNormal];
  1428. RASingleton.sharedInstance.price_type=2;
  1429. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  1430. int count = [section[@"count"] intValue];
  1431. for(int i=0;i<count;i++)
  1432. {
  1433. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1434. item[@"price"]= item[@"price2"];
  1435. item[@"unit_price"]= item[@"price2"];
  1436. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  1437. }
  1438. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  1439. RASingleton.sharedInstance.scan_cart[@"price_type"] = @2;
  1440. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  1441. [self.cartIndicatorBar removeFromSuperview];
  1442. self.cartIndicatorBar = [self setupCartIndicatorBar];
  1443. [self.view addSubview:self.cartIndicatorBar];
  1444. [self reload_data];
  1445. }];
  1446. UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1447. }];
  1448. [alertControl addAction:action1];
  1449. [alertControl addAction:action2];
  1450. // [alertControl addAction:action3];
  1451. // [alertControl addAction:alertthree];
  1452. [alertControl addAction:alertCancel];
  1453. [self presentViewController:alertControl animated:YES completion:nil];
  1454. #endif
  1455. }
  1456. -(void) newoloorder
  1457. {
  1458. NSString *orderdir =[OLDataProvider getScanPath];
  1459. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1460. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1461. // appDelegate.order_code = order_code;
  1462. // if(appDelegate.user.length==0)
  1463. // {
  1464. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  1465. // return;
  1466. // }
  1467. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1468. // NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1469. // RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1470. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1471. appDelegate.can_set_cart_price = true;
  1472. appDelegate.can_see_price = true;
  1473. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1474. // NSString *documents = [paths objectAtIndex:0];
  1475. {
  1476. // [OLDataProvider moveScanTemp2Order];
  1477. // NSError *error = nil;
  1478. // bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:orderdir withIntermediateDirectories:YES attributes:nil error:&error];
  1479. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1480. // NSString * string = [checked componentsJoinedByString:@","];
  1481. // [params setValue:string forKey:@"cart2Checkbox"];
  1482. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1483. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1484. // __block NSMutableDictionary* block_dict = dict;
  1485. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1486. {
  1487. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1488. //block代码块取代了delegate
  1489. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1490. NSMutableDictionary* dict = nil;
  1491. // NSMutableDictionary* dict = nil;
  1492. NSString* ordertemplate = nil;
  1493. if([RADataProvider getSiteHasERP])
  1494. ordertemplate =@"e_order.json";
  1495. else
  1496. ordertemplate =@"e_order_noerp.json";
  1497. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1498. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1499. [RAUtils dicttofile:orderPath dict:dict];
  1500. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1501. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1502. [self scanPlaceOrder];
  1503. }];
  1504. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1505. NSMutableDictionary* dict = nil;
  1506. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1507. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1508. [RAUtils dicttofile:orderPath dict:dict];
  1509. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1510. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1511. [self scanPlaceOrder];
  1512. }];
  1513. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1514. appDelegate.order_code = nil;
  1515. DebugLog(@"No");
  1516. }];
  1517. [alertControl addAction:actionOne];
  1518. [alertControl addAction:alert2];
  1519. [alertControl addAction:alertthree];
  1520. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1521. [self presentViewController:alertControl animated:YES completion:nil];
  1522. DebugLog(@"%@",self.edit_select_arr);
  1523. }
  1524. else
  1525. {
  1526. NSMutableDictionary* dict = nil;
  1527. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1528. {
  1529. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1530. }
  1531. else
  1532. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1533. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1534. [RAUtils dicttofile:orderPath dict:dict];
  1535. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1536. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1537. [self scanPlaceOrder];
  1538. }
  1539. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1540. }
  1541. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1542. // mainvc.btnScan.enabled = true;
  1543. // [appDelegate updateScanButton:true];
  1544. }
  1545. -(void) newoloorder1
  1546. {
  1547. // NSString* order_code = RASingleton.sharedInstance.scan_temp_code;
  1548. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1549. // appDelegate.order_code = order_code;
  1550. // if(appDelegate.user.length==0)
  1551. // {
  1552. // [RAUtils message_alert:@"Please login first." title:@"Warring" controller:self];
  1553. // return;
  1554. // }
  1555. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  1556. // NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  1557. // RASingleton.sharedInstance.scan_cart=cartTemplate;//[[RAConvertor data2dict:json] mutableCopy];
  1558. // appDelegate.user_type = USER_ROLE_EMPLOYEE;
  1559. appDelegate.can_set_cart_price = true;
  1560. appDelegate.can_see_price = true;
  1561. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1562. // NSString *documents = [paths objectAtIndex:0];
  1563. {
  1564. NSString *orderdir =[OLDataProvider getScanPath];
  1565. // [OLDataProvider moveScanTemp2Order];
  1566. // NSError *error = nil;
  1567. // bool bsuccess=[[NSFileManager defaultManager] createDirectoryAtPath:orderdir withIntermediateDirectories:YES attributes:nil error:&error];
  1568. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1569. // NSString * string = [checked componentsJoinedByString:@","];
  1570. // [params setValue:string forKey:@"cart2Checkbox"];
  1571. // NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1572. // NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1573. // __block NSMutableDictionary* block_dict = dict;
  1574. if(appDelegate.user_type== USER_ROLE_EMPLOYEE)
  1575. {
  1576. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  1577. //block代码块取代了delegate
  1578. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  1579. NSMutableDictionary* dict = nil;
  1580. NSString* ordertemplate = nil;
  1581. if([RADataProvider getSiteHasERP])
  1582. ordertemplate =@"e_order.json";
  1583. else
  1584. ordertemplate =@"e_order_noerp.json";
  1585. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  1586. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1587. [RAUtils dicttofile:orderPath dict:dict];
  1588. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1589. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1590. [self scanPlaceOrder];
  1591. }];
  1592. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1593. NSMutableDictionary* dict = nil;
  1594. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  1595. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1596. [RAUtils dicttofile:orderPath dict:dict];
  1597. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1598. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1599. [self scanPlaceOrder];
  1600. }];
  1601. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1602. appDelegate.order_code = nil;
  1603. DebugLog(@"No");
  1604. }];
  1605. [alertControl addAction:actionOne];
  1606. [alertControl addAction:alert2];
  1607. [alertControl addAction:alertthree];
  1608. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  1609. [self presentViewController:alertControl animated:YES completion:nil];
  1610. DebugLog(@"%@",self.edit_select_arr);
  1611. }
  1612. else
  1613. {
  1614. NSMutableDictionary* dict = nil;
  1615. if([appDelegate.customerInfo[@"customer_cid"] stringValue].length ==0 )
  1616. {
  1617. dict=[OLDataProvider loadScanTemplate:@"nc_order.json"];
  1618. }
  1619. else
  1620. dict=[OLDataProvider loadScanTemplate:@"c_order.json"];
  1621. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1622. [RAUtils dicttofile:orderPath dict:dict];
  1623. NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  1624. [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  1625. [self scanPlaceOrder];
  1626. }
  1627. // NSMutableDictionary* dict=[OLDataProvider loadScanTemplate:@"scan_order.json"];
  1628. }
  1629. // MainViewController * mainvc=(MainViewController * )appDelegate.main_vc;
  1630. // mainvc.btnScan.enabled = true;
  1631. // [appDelegate updateScanButton:true];
  1632. }
  1633. -(void)newScanOrder1
  1634. {
  1635. //
  1636. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1637. //
  1638. //
  1639. // if(appDelegate.order_code.length>0)
  1640. // {
  1641. //// 当前订单先关闭
  1642. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1643. // appDelegate.order_code = nil;
  1644. // appDelegate.customerInfo = nil;
  1645. // RASingleton.sharedInstance.scan_cart = nil;
  1646. // appDelegate.contact_id = nil;
  1647. //// [appDelegate updateScanButton:false];
  1648. //
  1649. // [appDelegate update_count_mark];
  1650. // [appDelegate closeOrder];
  1651. //
  1652. // }
  1653. //
  1654. //
  1655. {
  1656. [self newoloorder1];
  1657. }
  1658. }
  1659. -(void)newScanOrder
  1660. {
  1661. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1662. //if(appDelegate.user.length<=0)
  1663. //{
  1664. // [RAUtils message_alert:@"Please select a sales first." title:@"Warring" controller:self];
  1665. // return;
  1666. //}
  1667. // if(appDelegate.order_code.length>0)
  1668. // {
  1669. //// 当前订单先关闭
  1670. //// [OLDataProvider deleteScanOrder:appDelegate.order_code];
  1671. // appDelegate.order_code = nil;
  1672. // appDelegate.customerInfo = nil;
  1673. // RASingleton.sharedInstance.scan_cart = nil;
  1674. // appDelegate.contact_id = nil;
  1675. //// [appDelegate updateScanButton:false];
  1676. //
  1677. // [appDelegate update_count_mark];
  1678. // [appDelegate closeOrder];
  1679. //
  1680. // }
  1681. // RASingleton.sharedInstance.enable_OfflineOrder = true;
  1682. // __block MainViewController *brself= self;
  1683. // if(appDelegate.contact_id.length<=0)
  1684. // {
  1685. //
  1686. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"New Offline Order" message:nil preferredStyle:UIAlertControllerStyleAlert];
  1687. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"With Offline Contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1688. //
  1689. //// if(appDelegate.order_code && appDelegate.order_code.length>0)
  1690. //// {
  1691. //// [RAUtils message_alert:@"Please close current order and try again." title:@"" controller:self];
  1692. //// }
  1693. //// NSLog(@"new click");
  1694. //
  1695. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1696. //
  1697. //// NSString *path = [[NSBundle mainBundle] pathForResource:@"editContact.json" ofType:nil];
  1698. //
  1699. // CustomerEditViewController * cuseditVC = [[CustomerEditViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  1700. // cuseditVC.bnewcustomer=true;
  1701. // cuseditVC.bolocustomer = true;
  1702. // cuseditVC.url_type = URL_FILE;
  1703. // cuseditVC.request_url=[OLDataProvider scanTemplatePath:@"scan_contact.json"];
  1704. //
  1705. // cuseditVC.params = params;
  1706. //
  1707. // cuseditVC.returnValue=^(NSMutableDictionary* value)
  1708. // {
  1709. // if(value==nil)
  1710. // {
  1711. // [RAUtils message_alert:@"Cannot create order without customer infomation." title:@"" controller:self];
  1712. // }
  1713. // else
  1714. // {
  1715. // NSString* contact_id=[[NSUUID new] UUIDString];
  1716. //
  1717. //
  1718. // //---------------- construct customer_contact----------------------
  1719. // NSString* customer_first_name = [value valueForKey:@"customer_first_name"];
  1720. // if(customer_first_name==nil)
  1721. // customer_first_name=@"";
  1722. //
  1723. // NSString* customer_last_name= [value valueForKey:@"customer_last_name"];
  1724. // if(customer_last_name==nil)
  1725. // customer_last_name=@"";
  1726. // NSString* customer_contact = [NSString stringWithFormat:@"%@ %@",customer_first_name,customer_last_name];
  1727. // customer_contact=[customer_contact stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  1728. // [value setValue:customer_contact forKey:@"customer_contact"];
  1729. //
  1730. //
  1731. //
  1732. // value [@"customer_cid"] = contact_id;
  1733. // appDelegate.contact_id=contact_id;
  1734. // appDelegate.customerInfo = value;
  1735. //
  1736. //
  1737. //
  1738. //
  1739. //
  1740. //
  1741. //// [brself refreshContactDisplay];
  1742. // [self newoloorder];
  1743. //
  1744. // [self scanPlaceOrder];
  1745. //
  1746. //// [brself switchToCart:nil];
  1747. //
  1748. // }
  1749. // };
  1750. //
  1751. //
  1752. // // cuseditVC.delegate=self;
  1753. // //
  1754. // // if(checked.count==count)
  1755. // // {
  1756. // // orderinfoVC.have_tail = true
  1757. // // }
  1758. //
  1759. // [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1760. // [self.navigationController pushViewController:cuseditVC animated:false];
  1761. //
  1762. //// [self dismissViewControllerAnimated:NO completion:^{
  1763. ////// [(UINavigationController*)[self parentViewController] pushViewController:cuseditVC animated:false];;
  1764. ////// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1765. ////
  1766. ////// [self pushViewController:cuseditVC animated:false];
  1767. //// }];
  1768. //
  1769. //// [[self navigationController] setNavigationBarHidden:NO animated:NO];
  1770. //// [self.navigationController pushViewController:cuseditVC animated:false];
  1771. //
  1772. //
  1773. // }];
  1774. //
  1775. //
  1776. //
  1777. // UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  1778. //
  1779. // }];
  1780. //
  1781. // [alertControl addAction:actionOne];
  1782. //
  1783. //// [alertControl addAction:alertthree];
  1784. // [alertControl addAction:alertCancel];
  1785. //
  1786. // [self presentViewController:alertControl animated:YES completion:nil];
  1787. // }
  1788. // else
  1789. {
  1790. [self newoloorder];
  1791. }
  1792. }
  1793. -(void)placeOrder
  1794. {
  1795. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1796. #ifndef SCANNER_ORDER
  1797. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  1798. if (![RASingleton sharedInstance].permissions_edit_order) {
  1799. return;
  1800. }
  1801. // if (!self.available) {
  1802. //
  1803. // [RAUtils message_alert:@"There are some products is not available" title:@"Warning" controller:self];
  1804. // return;
  1805. // }
  1806. }
  1807. #endif
  1808. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  1809. bool have_free = false;
  1810. long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  1811. if(count==0)
  1812. {
  1813. [RAUtils message_alert:@"Add some model first." title:@"Cart Is Empty." controller:self] ;
  1814. return;
  1815. }
  1816. for(int i=0;i<count;i++)
  1817. {
  1818. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  1819. // bool check = [[item_json valueForKey:@"check"] boolValue];
  1820. NSString* product_id = [item_json valueForKey:@"product_id"];
  1821. // if(check)
  1822. // {
  1823. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  1824. //
  1825. // }
  1826. if(product_id.length==0)
  1827. {
  1828. [RAUtils message_alert:@"Some models in cart does not exist, you must remove them before place order." title:@"No Such Model" controller:self] ;
  1829. return;
  1830. }
  1831. bool is_free = [[item_json valueForKey:@"is_free"]boolValue];
  1832. if(is_free)
  1833. have_free=true;
  1834. }
  1835. // disable for debug
  1836. // if(checked.count==0)
  1837. // {
  1838. // [RAUtils message_alert:@"You must select at least one model." title:@"Cannot Place Order" controller:self] ;
  1839. // return;
  1840. // }
  1841. // NSDictionary * freejson = [self.content_data objectForKey:@"freeGiveaway"];
  1842. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1843. /* FREE GIVE AWAY
  1844. int free_count = [[self.freejson valueForKey:@"count"]intValue];
  1845. for(int ic=free_count-1;ic>=0;ic--)
  1846. {
  1847. float compare_price = [[self.freejson valueForKey:[NSString stringWithFormat:@"item_%d",ic]] floatValue];
  1848. if(self.total>=compare_price && !have_free&&appDelegate.can_set_cart_price)
  1849. {
  1850. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away available.", nil) message:[NSString stringWithFormat:@"Order total price more than %.2f, do you want to add free give away item before place order?", compare_price] delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  1851. alert.tag = ALERT_FREE;
  1852. [alert show];
  1853. return;
  1854. }
  1855. }
  1856. */
  1857. #ifdef SCANNER_ORDER
  1858. if(appDelegate.bLogin==false)
  1859. {
  1860. LoginViewController * loginvc =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginViewController"];
  1861. // loginvc.delegate = self;
  1862. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  1863. loginvc.returnValue = ^(bool blogin){
  1864. if(blogin)
  1865. {
  1866. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1867. if(appDelegate.order_code.length==0)
  1868. {
  1869. [self newScanOrder];
  1870. }
  1871. }
  1872. };
  1873. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:loginvc] ;
  1874. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  1875. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  1876. [self presentViewController:navi animated:YES completion:^{
  1877. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  1878. DebugLog(@"LoginViewController present.........");
  1879. // self.btop = false;
  1880. // <#code#>
  1881. }];
  1882. return;
  1883. }
  1884. else
  1885. {
  1886. NSString *orderdir =[OLDataProvider getScanPath];
  1887. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  1888. if(appDelegate.order_code.length==0 )
  1889. {
  1890. [self newScanOrder];
  1891. }
  1892. else if( ![[NSFileManager defaultManager] fileExistsAtPath:orderPath])
  1893. {
  1894. [self newScanOrder1];
  1895. }
  1896. else
  1897. {
  1898. [self scanPlaceOrder];
  1899. //place order
  1900. }
  1901. return;
  1902. }
  1903. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  1904. // {
  1905. //
  1906. // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  1907. // // NSString * string = [checked componentsJoinedByString:@","];
  1908. // // [params setValue:string forKey:@"cart2Checkbox"];
  1909. //
  1910. //// NSData* data=[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_ORDER ofType:@"json" ]];
  1911. //// NSError *error=nil;
  1912. //// NSMutableDictionary* dict=[[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error] mutableCopy];
  1913. ////
  1914. //
  1915. //
  1916. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  1917. // NSString *documents = [paths objectAtIndex:0];
  1918. //
  1919. //
  1920. //
  1921. // NSString *orderdir = [documents stringByAppendingPathComponent:appDelegate.order_code];
  1922. //
  1923. // NSMutableDictionary* dict= [[RAUtils dictfromfile:[orderdir stringByAppendingPathComponent:@"order.json"]] mutableCopy];
  1924. //
  1925. // int section_count = [dict[@"section_count"] intValue];
  1926. //
  1927. // for(int i=0;i<section_count;i++)
  1928. // {
  1929. // NSMutableDictionary* section = [dict[[NSString stringWithFormat:@"section_%d",i]] mutableCopy];
  1930. // NSString* title = section[@"title"];
  1931. // if([title isEqualToString:@"Model Information"])
  1932. // {
  1933. //
  1934. // NSMutableDictionary* cart_section = RASingleton.sharedInstance.scan_cart[@"section_0"];
  1935. // int cart_count = [cart_section[@"count"] intValue];
  1936. // for(int j=0;j<cart_count;j++)
  1937. // {
  1938. // NSMutableDictionary* cart_item = [cart_section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1939. // cart_item[@"control"]=@"model";
  1940. // section[[NSString stringWithFormat:@"item_%d",j]] = cart_item;
  1941. //
  1942. // }
  1943. // section[@"count"] = @(cart_count);
  1944. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1945. // }
  1946. // else
  1947. // if([title isEqualToString:@"Customer"])
  1948. // {
  1949. //
  1950. // int scount = [section[@"count"] intValue];
  1951. // for(int j=0;j<scount;j++)
  1952. // {
  1953. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1954. // NSString * name = item[@"name"];
  1955. //
  1956. // if([name isEqualToString:@"business_card"])
  1957. // {
  1958. // NSArray*arr =[RAConvertor string2arr:appDelegate.customerInfo[name] separator:@","];
  1959. // for(int l=0;l<arr.count;l++)
  1960. // {
  1961. // item[[NSString stringWithFormat:@"img_url_%d",l] ]=arr[l];
  1962. // }
  1963. // }
  1964. // else
  1965. // item[@"value"]=appDelegate.customerInfo[name];
  1966. //
  1967. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1968. // }
  1969. //
  1970. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1971. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1972. //
  1973. //
  1974. // }
  1975. // else
  1976. // if([title isEqualToString:@"Remarks Content"])
  1977. // {
  1978. //
  1979. // int scount = [section[@"count"] intValue];
  1980. // for(int j=0;j<scount;j++)
  1981. // {
  1982. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  1983. // NSString * name = item[@"name"];
  1984. //
  1985. //
  1986. // if([name isEqualToString:@"comments"])
  1987. // {
  1988. // item[@"value"] = RASingleton.sharedInstance.scan_cart[@"general_note"];
  1989. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  1990. // }
  1991. //
  1992. //
  1993. // }
  1994. //
  1995. // // NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  1996. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  1997. //
  1998. //
  1999. // }
  2000. // else if([title isEqualToString:@"Order Total"])
  2001. // {
  2002. //
  2003. // int scount = [section[@"count"] intValue];
  2004. // for(int j=0;j<scount;j++)
  2005. // {
  2006. // NSMutableDictionary * item = [section[[NSString stringWithFormat:@"item_%d",j]] mutableCopy];
  2007. // NSString * name = item[@"name"];
  2008. //
  2009. //
  2010. // if([name isEqualToString:@"totalPrice"])
  2011. // {
  2012. // item[@"value"] = [NSString stringWithFormat:@"%.2f",self.total];
  2013. // section[[NSString stringWithFormat:@"item_%d",j]] = item;
  2014. // }
  2015. //
  2016. //
  2017. // }
  2018. //
  2019. //// NSDictionary* item_0=@{@"control":@"text",@"name":@"customer_cid",@"aname":@"Contact",@"value":appDelegate.contact_id};
  2020. // dict[[NSString stringWithFormat:@"section_%d",i]] = section;
  2021. //
  2022. //
  2023. //
  2024. // }
  2025. //
  2026. //
  2027. //
  2028. //
  2029. // }
  2030. //
  2031. //// NSString *path = NSTemporaryDirectory();
  2032. ////
  2033. //// NSString* file=[NSString stringWithFormat:@"SO_%@.json",appDelegate.order_code];
  2034. //// NSString *filePath = [path stringByAppendingPathComponent:file];
  2035. ////
  2036. ////
  2037. ////
  2038. // [RAUtils dicttofile:[orderdir stringByAppendingPathComponent:@"order.json"] dict:dict];
  2039. //
  2040. // CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2041. //
  2042. //
  2043. //
  2044. // orderinfoVC.disable_dropdown_refresh=true;
  2045. // orderinfoVC.url_type = URL_FILE;
  2046. // orderinfoVC.request_url=[orderdir stringByAppendingPathComponent:@"order.json"];
  2047. //
  2048. // orderinfoVC.params = params;
  2049. // orderinfoVC.title=@"";
  2050. // orderinfoVC.delegate=self;
  2051. // //
  2052. // // if(checked.count==count)
  2053. // // {
  2054. // // orderinfoVC.have_tail = true
  2055. // // }
  2056. //
  2057. // [self.navigationController pushViewController:orderinfoVC animated:true];
  2058. //
  2059. // return;
  2060. // }
  2061. #endif
  2062. #ifdef BACKORDER_PROCESS
  2063. if (self.back_order_flag) {
  2064. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2065. [params setObject:@(0) forKey:@"step"];
  2066. RAOrderEditorViewController *orderEditorVC =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Order" bundle:nil] instantiateViewControllerWithIdentifier:@"RAOrderEditorViewController"];
  2067. //[[RAOrderEditorViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2068. orderEditorVC.disable_dropdown_refresh=true;
  2069. orderEditorVC.url_type = URL_REMOTE;
  2070. orderEditorVC.request_url=URL_CARTDELIVERY;
  2071. orderEditorVC.params = params;
  2072. orderEditorVC.delegate=self;
  2073. orderEditorVC.title=@"";
  2074. [self.navigationController pushViewController:orderEditorVC animated:true];
  2075. }
  2076. else
  2077. #endif
  2078. {
  2079. NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2080. // NSString * string = [checked componentsJoinedByString:@","];
  2081. // [params setValue:string forKey:@"cart2Checkbox"];
  2082. CreateOrderViewController * orderinfoVC = [[CreateOrderViewController alloc] initWithNibName:@"CommonEditor.iPad" bundle:nil];
  2083. orderinfoVC.disable_dropdown_refresh=true;
  2084. orderinfoVC.url_type = URL_REMOTE;
  2085. orderinfoVC.request_url=URL_CARTDELIVERY;
  2086. orderinfoVC.params = params;
  2087. orderinfoVC.title=@"";
  2088. orderinfoVC.delegate=self;
  2089. //
  2090. // if(checked.count==count)
  2091. // {
  2092. // orderinfoVC.have_tail = true
  2093. // }
  2094. [self.navigationController pushViewController:orderinfoVC animated:true];
  2095. }
  2096. }
  2097. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
  2098. {
  2099. return NO;
  2100. }
  2101. //- (IBAction)onDelete:(UIButton *)sender {
  2102. // return ;
  2103. // NSMutableArray* checked = [[NSMutableArray alloc] init];
  2104. //
  2105. //
  2106. //
  2107. // long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2108. // for(int i=0;i<count;i++)
  2109. // {
  2110. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2111. // bool check = [[item_json valueForKey:@"check"] boolValue];
  2112. // if(check)
  2113. // {
  2114. // [checked addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2115. //
  2116. // }
  2117. // }
  2118. // // disable for debug
  2119. // if(checked.count==0)
  2120. // return;
  2121. //
  2122. // // NSMutableDictionary * params= [[NSMutableDictionary alloc] init];
  2123. // NSString * string = [checked componentsJoinedByString:@","];
  2124. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2125. //
  2126. // NSDictionary* cart_json = [RANetwork cart_remove:string];
  2127. //
  2128. // dispatch_async(dispatch_get_main_queue(), ^{
  2129. //
  2130. //
  2131. //
  2132. // if([[cart_json valueForKey:@"result"] intValue]==2)
  2133. // {
  2134. //
  2135. // [self reload_data];
  2136. // }
  2137. // else
  2138. // {
  2139. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  2140. // }
  2141. //
  2142. //
  2143. //
  2144. // });
  2145. // });
  2146. //}
  2147. - (IBAction)onScanDiscount:(UIButton*)sender {
  2148. #ifdef SCANNER_ORDER
  2149. UITableViewCell* cell =(UITableViewCell*) sender.superview.superview;
  2150. NSIndexPath * indexPath = [self.itemListTable indexPathForCell:cell];
  2151. UIViewController* parentvc=self;
  2152. // EditModelPriceViewController
  2153. ScanDiscountViewController * vc =[[UIStoryboard storyboardWithName:@"SO" bundle:nil] instantiateViewControllerWithIdentifier:@"ScanDiscountViewController"];
  2154. NSMutableDictionary * item_json = nil;
  2155. if (self.back_order_flag) {
  2156. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  2157. } else {
  2158. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2159. }
  2160. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  2161. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  2162. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  2163. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  2164. // vc.delegate = parentvc.self;
  2165. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2166. vc.onSetValue = ^(double price,double discount){
  2167. bool bmodify=false;
  2168. if(discount>0)
  2169. bmodify=true;
  2170. // NSString* notes = [item_json valueForKey:@"note"];
  2171. // if(notes.length==0)
  2172. // notes=@"";
  2173. // if(bmodify)
  2174. // {
  2175. //
  2176. //
  2177. // // if([notes isEqualToString:@""])
  2178. //// notes=[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2179. ////
  2180. //// NSRange range;
  2181. //// range = [notes rangeOfString:@"PRICE MODIFIED"];
  2182. //// if (range.location != NSNotFound) {
  2183. ////
  2184. //// }else{
  2185. //// notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  2186. //// }
  2187. // }
  2188. // else
  2189. //
  2190. // {
  2191. //// notes =@"";
  2192. // }
  2193. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  2194. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:nil completionHandler:^(NSMutableDictionary *result) {
  2195. NSDictionary* cart_json = result;
  2196. [waitalert dismissViewControllerAnimated:YES completion:^{
  2197. if([[cart_json valueForKey:@"result"] intValue]==2)
  2198. {
  2199. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  2200. //
  2201. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  2202. // [item_json setValue:notes forKey:@"note"];
  2203. // RASingleton.sharedInstance.scan_cart[@"section_0"][[NSString stringWithFormat:@"item_%d",indexPath.row]]=item_json;
  2204. // if (self.back_order_flag) {
  2205. // [self updateItemJson:item_json atIndexPath:indexPath];
  2206. // } else {
  2207. // self.content_arr[indexPath.row ] = item_json;
  2208. // }
  2209. // tableView.editing = false;
  2210. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  2211. // [self refresh_total];
  2212. [self reload_data];
  2213. #ifdef RA_NOTIFICATION
  2214. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2215. #else
  2216. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2217. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2218. #endif
  2219. }
  2220. else
  2221. {
  2222. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  2223. }
  2224. }];
  2225. }];
  2226. }];
  2227. };
  2228. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2229. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2230. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2231. [parentvc presentViewController:navi animated:YES completion:^{
  2232. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2233. DebugLog(@"EditModelPriceViewController present.........");
  2234. // self.btop = false;
  2235. // <#code#>
  2236. }];
  2237. #endif
  2238. }
  2239. -(void)refresh_total
  2240. {
  2241. self.total=0;
  2242. self.total_carton=0;
  2243. self.total_cuft=0;
  2244. self.total_weight=0;
  2245. self.total_QTY=0;
  2246. self.total_item=0;
  2247. self.surcharge=0;
  2248. #ifdef SCANNER_ORDER
  2249. NSString* pricename;
  2250. NSDictionary *addressDic = [[NSUserDefaults standardUserDefaults] valueForKey:@"ScanAddress"];
  2251. NSString* servername = [addressDic objectForKey:@"show_name"];
  2252. NSArray* arrsn = [RAConvertor string2arr:servername separator:@","];
  2253. NSString * shortname = arrsn[0];
  2254. if(shortname.length==0)
  2255. shortname = servername;
  2256. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2257. NSDictionary* price_group = [RADataProvider get_price_group:appDelegate.price_group];
  2258. switch(RASingleton.sharedInstance.price_type )
  2259. {
  2260. case 0: pricename =price_group[@"price_0"][@"display"];//@"DDP";//[NSString stringWithFormat:@"%@_DDP",shortname];
  2261. break;;
  2262. case 1: pricename =price_group[@"price_1"][@"display"];//@"WHSE";//[NSString stringWithFormat:@"%@_WHSE",shortname];;
  2263. break;;
  2264. // case 2: pricename = @"25%";
  2265. // break;
  2266. }
  2267. [self.btnPrice setTitle:pricename forState:UIControlStateNormal];
  2268. // self.cartIndicatorBar = [self setupCartIndicatorBar];
  2269. [self.cartIndicatorBar removeFromSuperview];
  2270. self.cartIndicatorBar = [self setupCartIndicatorBar];
  2271. [self.view addSubview:self.cartIndicatorBar];
  2272. #endif
  2273. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2274. for(int i=0;i<count;i++)
  2275. {
  2276. NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2277. bool bcheck = [[item_json valueForKey:@"check"]boolValue];
  2278. if(bcheck)
  2279. {
  2280. double unitprice = [[item_json valueForKey:@"unit_price"] doubleValue];
  2281. double discount = [[item_json valueForKey:@"discount"] doubleValue];
  2282. int count=[[item_json valueForKey:@"count"] intValue];
  2283. double totalprice =count*unitprice*(1-discount/100.0);
  2284. double cuft=[[item_json valueForKey:@"cuft"] doubleValue];
  2285. double weight=[[item_json valueForKey:@"weight"] doubleValue];
  2286. int carton=/*count**/[[item_json valueForKey:@"carton"] intValue];
  2287. int item_count=1;
  2288. int item_qty=1;
  2289. // NSDictionary * bundle_item =[item_json objectForKey:@"combine"];
  2290. double msurcharge =0;
  2291. if(RASingleton.sharedInstance.price_type==1)
  2292. {
  2293. if([item_json[@"special_price"] boolValue])
  2294. {
  2295. msurcharge=([item_json[price_group[@"price_3"][@"name"]] doubleValue]-[item_json[price_group[@"price_2"][@"name"]] doubleValue])*count*(1-discount/100.0);
  2296. if(msurcharge<0)
  2297. msurcharge = 0;
  2298. }
  2299. else
  2300. {
  2301. msurcharge=([item_json[price_group[@"price_3"][@"name"]] doubleValue]-[item_json[price_group[@"price_1"][@"name"]] doubleValue])*count*(1-discount/100.0);
  2302. if(msurcharge<0)
  2303. msurcharge = 0;
  2304. }
  2305. }
  2306. // double dprice=0;
  2307. // if(bundle_item!=nil)
  2308. // {
  2309. // // int citem=0;
  2310. //
  2311. // int bcount=[[bundle_item valueForKey:@"count"] intValue];
  2312. // for(int bc=0;bc<bcount;bc++)
  2313. // {
  2314. // NSDictionary * bitem = [bundle_item objectForKey:[NSString stringWithFormat:@"item_%d",bc]];
  2315. // int modulus= [[bitem valueForKey:@"modulus"] intValue];
  2316. // // citem+= modulus;
  2317. // item_count+=1;
  2318. // item_qty+=modulus;
  2319. // double uprice= [[bitem valueForKey:@"unit_price"]doubleValue];
  2320. // dprice+= uprice*modulus*count;
  2321. //
  2322. // }
  2323. // }
  2324. // totalprice+= dprice;
  2325. self.surcharge+=msurcharge;
  2326. self.total+=totalprice;
  2327. self.total_cuft+=cuft;
  2328. self.total_carton+=carton;
  2329. self.total_weight+=weight;
  2330. self.total_item+=item_count;
  2331. self.total_QTY+=(item_qty)*count;
  2332. }
  2333. }
  2334. NSString* subtotal = [RAConvertor currencyNumber:self.total];//[NSString stringWithFormat:@"$%@",];
  2335. NSString* subcuft = [NSString stringWithFormat:@"%.2f",self.total_cuft];
  2336. NSString* subcarton = [NSString stringWithFormat:@"%d",self.total_carton];
  2337. NSString* subweight = [NSString stringWithFormat:@"%.2f lbs",self.total_weight];
  2338. NSString* surcharge = [RAConvertor currencyNumber:self.surcharge];//[NSString stringWithFormat:@"$%@",];
  2339. NSString* totalprice = [RAConvertor currencyNumber:(self.total+self.surcharge)];//[NSString stringWithFormat:@"$%@",];
  2340. NSString* subitems = [NSString stringWithFormat:@"%d",self.total_item];
  2341. NSString* subqty = [NSString stringWithFormat:@"%d",self.total_QTY];
  2342. #ifndef SCANNER_ORDER
  2343. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2344. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  2345. {
  2346. }
  2347. else
  2348. {
  2349. subtotal=nil;
  2350. }
  2351. #else
  2352. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2353. [OLDataProvider updateScanOrder:appDelegate.order_code];
  2354. #endif
  2355. self.labelTotalSurcharge.text = surcharge;
  2356. self.labelTotalPrice.text = totalprice;
  2357. self.labelTotal.text=subtotal;
  2358. self.label_cuft.text=subcuft;
  2359. self.label_carton.text=subcarton;
  2360. self.label_weight.text=subweight;
  2361. self.label_items.text = subitems;
  2362. self.label_qty.text = subqty;
  2363. self.label_notes.text = [self.notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "];
  2364. }
  2365. - (IBAction)onEditGeneralNotes:(id)sender {
  2366. #ifndef SCANNER_ORDER
  2367. if (![self isOrderAvailable]) {
  2368. return;
  2369. }
  2370. #endif
  2371. UIViewController* parentvc=self;
  2372. CartGeneralNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"CartGeneralNotesViewController"];
  2373. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row ] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2374. vc.notes=self.notes;
  2375. // vc.delegate = parentvc.self;
  2376. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  2377. vc.onSetValue = ^(NSString* notes){
  2378. self.notes = notes;
  2379. [self refresh_total];
  2380. };
  2381. //
  2382. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  2383. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  2384. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  2385. [parentvc presentViewController:navi animated:YES completion:^{
  2386. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  2387. DebugLog(@"general notes editor present.........");
  2388. // self.btop = false;
  2389. // <#code#>
  2390. }];
  2391. }
  2392. //- (IBAction)onSelectAll:(UIButton *)sender {
  2393. //
  2394. //
  2395. // NSMutableArray* arr_ids = [[NSMutableArray alloc] init];
  2396. //
  2397. //
  2398. //
  2399. //
  2400. //
  2401. //
  2402. // if([self.btnselect.titleLabel.text isEqualToString:@"Select all"])
  2403. // {
  2404. //
  2405. // long count = self.content_arr.count;// [[self.content_data valueForKey:@"count"] intValue];
  2406. // for(int i=0;i<count;i++)
  2407. // {
  2408. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2409. // if(![[item_json valueForKey:@"check"] boolValue])
  2410. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2411. //
  2412. // }
  2413. // [self.btnselect setTitle: @"Deselect all" forState: UIControlStateNormal];
  2414. // }
  2415. // else
  2416. // {
  2417. // long count = self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2418. // for(int i=0;i<count;i++)
  2419. // {
  2420. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy]; //[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  2421. // if([[item_json valueForKey:@"check"] boolValue])
  2422. // [arr_ids addObject:[NSNumber numberWithInt:[[item_json valueForKey:@"cart_item_id"] intValue]]];
  2423. //
  2424. // }
  2425. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  2426. // }
  2427. //
  2428. // NSString * ids = [arr_ids componentsJoinedByString:@","];
  2429. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2430. //
  2431. //
  2432. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  2433. //
  2434. // dispatch_async(dispatch_get_main_queue(), ^{
  2435. //
  2436. //
  2437. //
  2438. // if([[check_json valueForKey:@"result"] intValue]==2)
  2439. // {
  2440. //
  2441. // long count = self.content_arr.count;
  2442. // for(int i=0;i<count;i++)
  2443. // {
  2444. // NSMutableDictionary * item_json = [self.content_arr[i] mutableCopy];
  2445. // if([item_json[@"check"] boolValue])
  2446. // item_json[@"check"]= @"false";
  2447. // else
  2448. // item_json[@"check"]= @"true";
  2449. //
  2450. // self.content_arr[i] = item_json;
  2451. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%d",i]];
  2452. // }
  2453. //
  2454. // [self reload_container_getdata:false];
  2455. //
  2456. // // [self reload_data];
  2457. // }
  2458. // else
  2459. // {
  2460. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  2461. // }
  2462. //
  2463. //
  2464. //
  2465. // });
  2466. // });
  2467. //
  2468. //
  2469. //
  2470. //
  2471. //
  2472. //
  2473. // // [self refresh_total];
  2474. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  2475. // // DebugLog(self.btnselect.titleLabel.text);
  2476. // // if(self.btnselect.titleLabel.text)
  2477. //}
  2478. //#pragma mark - MODEL cell delegate
  2479. //-(void) returnQTY:(int)qty
  2480. //{
  2481. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2482. //
  2483. // int count=[[item_json valueForKey:@"count"] intValue];
  2484. //
  2485. // if(count==qty)
  2486. // return;
  2487. // [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2488. // double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2489. // // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2490. // [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  2491. // self.content_arr[indexPath.row]= item_json;
  2492. // // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2493. // [self refresh_total];
  2494. // // self.total+=(unit_price*qty-sub_total);
  2495. // // self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  2496. //
  2497. //
  2498. //}
  2499. - (IBAction)OnCancelOrderClicked:(id)sender {
  2500. // if (![self isOrderAvailable]) {
  2501. // return;
  2502. // }
  2503. //
  2504. // UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Cancel Order" message:@"Are you sure to cancel the order in cart ?" preferredStyle:UIAlertControllerStyleAlert];
  2505. // //block代码块取代了delegate
  2506. //
  2507. //
  2508. //
  2509. // UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2510. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2511. // __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Cancel Order" completion:^{
  2512. //
  2513. //#ifdef SCANNER_ORDER
  2514. //// if(RASingleton.sharedInstance.enable_OfflineOrder)
  2515. // {
  2516. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  2517. // [OLDataProvider deleteScanOrder:appDelegate.order_code];
  2518. // [appDelegate closeOrder];
  2519. // return;
  2520. // }
  2521. //#endif
  2522. // [RANetwork request_cancel_order:nil order_code:appDelegate.order_code completionHandler:^(NSMutableDictionary *result) {
  2523. // [waitalert dismissViewControllerAnimated:YES completion:^{
  2524. // NSDictionary* return_json = result;
  2525. //
  2526. // if([[return_json valueForKey:@"result"] intValue]==2)
  2527. // {
  2528. // //if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  2529. // {
  2530. // appDelegate.order_code = nil;
  2531. // //appDelegate.user_type = 0;
  2532. // appDelegate.customerInfo = nil;
  2533. // appDelegate.contact_id = nil;
  2534. // appDelegate.order_customer_id = nil;
  2535. // [appDelegate SetSo:nil];
  2536. // appDelegate.cart_count=0;
  2537. // [appDelegate update_count_mark];
  2538. //
  2539. //
  2540. // }
  2541. // #ifdef RA_NOTIFICATION
  2542. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2543. // #else
  2544. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2545. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2546. // #endif
  2547. // //[RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  2548. // //[self ReloadData];
  2549. //
  2550. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2551. // // // appDelegate.order_code = nil;
  2552. // //
  2553. // // [appDelegate closeOrder];
  2554. // // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2555. // [((MainViewController*)appDelegate.main_vc) switchToHome];
  2556. //
  2557. // // if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2558. // // {
  2559. // // [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2560. // // }
  2561. // }
  2562. // else
  2563. // {
  2564. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  2565. // }
  2566. // }];
  2567. //
  2568. //
  2569. //
  2570. //
  2571. //
  2572. //
  2573. // }];
  2574. //
  2575. // }];
  2576. //
  2577. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2578. ////
  2579. //// NSDictionary* return_json = [RANetwork cancel_Order:nil order_code:appDelegate.order_code];
  2580. ////
  2581. //// dispatch_async(dispatch_get_main_queue(), ^{
  2582. //// [waitalert dismissViewControllerAnimated:YES completion:nil];
  2583. ////
  2584. ////
  2585. //// if([[return_json valueForKey:@"result"] intValue]==2)
  2586. //// {
  2587. //// //if([appDelegate.order_code isEqualToString: [self.content_data[indexPath.row] valueForKey:@"order_code"]])
  2588. //// {
  2589. //// appDelegate.order_code= nil;
  2590. //// //appDelegate.user_type = 0;
  2591. //// appDelegate.customerInfo = nil;
  2592. //// appDelegate.contact_id = nil;
  2593. //// appDelegate.order_customer_id = nil;
  2594. //// [appDelegate SetSo:nil];
  2595. //// appDelegate.cart_count=0;
  2596. //// [appDelegate update_count_mark];
  2597. ////
  2598. ////
  2599. //// }
  2600. ////#ifdef RA_NOTIFICATION
  2601. //// [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2602. ////#else
  2603. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2604. //// [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2605. ////#endif
  2606. //// //[RAUtils message_alert:nil title:@"Order Canceled" controller:self] ;
  2607. //// //[self ReloadData];
  2608. ////
  2609. ////// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2610. ////// // appDelegate.order_code = nil;
  2611. //////
  2612. ////// [appDelegate closeOrder];
  2613. ////// [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  2614. //// [((MainViewController*)appDelegate.main_vc) switchToHome];
  2615. ////
  2616. ////// if([appDelegate.mode isEqualToString:@"TM"]&& appDelegate.submit_order_logout)
  2617. ////// {
  2618. ////// [((MainViewController*)appDelegate.main_vc) Loginout:false];
  2619. ////// }
  2620. //// }
  2621. //// else
  2622. //// {
  2623. //// [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Cancel Order" controller:self] ;
  2624. //// }
  2625. ////
  2626. ////
  2627. ////
  2628. ////
  2629. //// });
  2630. //// });
  2631. //
  2632. //
  2633. // }];
  2634. //
  2635. // UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2636. // DebugLog(@"No");
  2637. // }];
  2638. // [alertControl addAction:actionOne];
  2639. //
  2640. // [alertControl addAction:alertthree];
  2641. //
  2642. // //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2643. //
  2644. //
  2645. // [self presentViewController:alertControl animated:YES completion:nil];
  2646. //
  2647. // DebugLog(@"%@",self.edit_select_arr);
  2648. //
  2649. //
  2650. }
  2651. #pragma mark - Private
  2652. - (BOOL)isOrderAvailable {
  2653. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2654. if (appDelegate.order_code.length == 0) {
  2655. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"please create a new order first" preferredStyle:UIAlertControllerStyleAlert];
  2656. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2657. }];
  2658. [alertVC addAction:okAction];
  2659. [self presentViewController:alertVC animated:YES completion:nil];
  2660. return NO;
  2661. }
  2662. return YES;
  2663. }
  2664. #pragma mark - commoneditor controller delegate
  2665. -(void) returnValue:(NSMutableDictionary *)value indexPath :(NSIndexPath*) indexPath
  2666. {
  2667. // [self reload_data];
  2668. if([value[@"commitorder_logout"] boolValue])
  2669. [self logout];
  2670. [[self navigationController] setNavigationBarHidden:YES animated:NO];
  2671. }
  2672. #pragma mark - Table view data source
  2673. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  2674. {
  2675. NSDictionary * item_json = nil;
  2676. if (self.back_order_flag) {
  2677. item_json = [self itemJsonAtIndexPath:indexPath];
  2678. } else {
  2679. item_json = self.content_arr[indexPath.row ];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2680. }
  2681. NSString* notes =[item_json valueForKey:@"note"];
  2682. if(notes.length>0)
  2683. {
  2684. return 146;
  2685. }
  2686. else
  2687. return 120;
  2688. }
  2689. //- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2690. //{
  2691. // return 0;
  2692. //}
  2693. //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  2694. //{
  2695. // return 0;
  2696. //}
  2697. //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  2698. //{
  2699. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2700. // return myView;
  2701. //
  2702. //}
  2703. //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2704. //{
  2705. // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.0001)];
  2706. //// myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
  2707. //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
  2708. //// titleLabel.textColor=[UIColor whiteColor];
  2709. //// titleLabel.backgroundColor = [UIColor clearColor];
  2710. //// if(section==0)
  2711. //// titleLabel.text=NSLocalizedString(@"display_items", nil);
  2712. //// else
  2713. //// titleLabel.text=NSLocalizedString(@"hide_items", nil);
  2714. //// [titleLabel sizeToFit];
  2715. //// [myView addSubview:titleLabel];
  2716. ////
  2717. // return myView;
  2718. //}
  2719. //
  2720. //- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  2721. // if(section==0)
  2722. // return nil;
  2723. // else
  2724. // return @"detail section";
  2725. //}
  2726. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  2727. {
  2728. if (self.back_order_flag) {
  2729. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  2730. } else {
  2731. return 1;
  2732. }
  2733. }
  2734. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  2735. {
  2736. #ifdef SCANNER_ORDER
  2737. return 0;
  2738. #endif
  2739. if (self.back_order_flag) {
  2740. return 50;
  2741. } else {
  2742. return 0;
  2743. }
  2744. }
  2745. - (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  2746. {
  2747. #ifdef SCANNER_ORDER
  2748. return nil;
  2749. #endif
  2750. if (self.back_order_flag) {
  2751. // UIView *header = [tableView dequeueReusableCellWithIdentifier:@"section_header_cell"];
  2752. // UILabel *title_lb = [header viewWithTag:8520];
  2753. UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 50.0f)];
  2754. header.backgroundColor = [UIColor colorWithRed:128 / 255.0 green:95 / 255.0 blue:54 / 255.0 alpha:1];
  2755. header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2756. UILabel *title_lb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(header.bounds) - 10, 50.0f)];
  2757. title_lb.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  2758. title_lb.font = [UIFont systemFontOfSize:25.0f];
  2759. title_lb.textColor = [UIColor whiteColor];
  2760. [header addSubview:title_lb];
  2761. title_lb.text = [self titleForSection:section];
  2762. return header;
  2763. } else {
  2764. return nil;
  2765. }
  2766. }
  2767. #ifdef SCANNER_ORDER
  2768. - (IBAction)onScanChangeCustomerType:(id)sender {
  2769. return;
  2770. NSString *orderdir =[OLDataProvider getScanPath];
  2771. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:@"Select Customer type" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  2772. //block代码块取代了delegate
  2773. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Existing Customer" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  2774. NSMutableDictionary* dict = nil;
  2775. NSString* ordertemplate = nil;
  2776. if([RADataProvider getSiteHasERP])
  2777. ordertemplate =@"e_order.json";
  2778. else
  2779. ordertemplate =@"e_order_noerp.json";
  2780. dict=[OLDataProvider loadScanTemplate:ordertemplate];
  2781. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2782. [RAUtils dicttofile:orderPath dict:dict];
  2783. //
  2784. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2785. //
  2786. //
  2787. //
  2788. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2789. //
  2790. // [self scanPlaceOrder];
  2791. //
  2792. }];
  2793. UIAlertAction *alert2 = [UIAlertAction actionWithTitle:@"New customer" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  2794. NSMutableDictionary* dict = nil;
  2795. dict=[OLDataProvider loadScanTemplate:@"n_order.json"];
  2796. NSString *orderPath = [orderdir stringByAppendingPathComponent:@"order.json"];
  2797. [RAUtils dicttofile:orderPath dict:dict];
  2798. //
  2799. //
  2800. // NSString *contactpath = [orderdir stringByAppendingPathComponent:@"contact.json"];
  2801. //
  2802. //
  2803. //
  2804. // [RAUtils dicttofile:contactpath dict:appDelegate.customerInfo];
  2805. // [self scanPlaceOrder];
  2806. }];
  2807. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  2808. DebugLog(@"No");
  2809. }];
  2810. [alertControl addAction:actionOne];
  2811. [alertControl addAction:alert2];
  2812. [alertControl addAction:alertthree];
  2813. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  2814. [self presentViewController:alertControl animated:YES completion:nil];
  2815. DebugLog(@"%@",self.edit_select_arr);
  2816. }
  2817. #endif
  2818. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  2819. {
  2820. if (self.back_order_flag) {
  2821. return [self itemCountInSection:section];
  2822. } else {
  2823. // NSDictionary * item_json = [self.content_data objectForKey:@"items"];
  2824. long count =self.content_arr.count;//[[self.content_data valueForKey:@"count"] intValue];
  2825. return count;
  2826. }
  2827. }
  2828. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  2829. {
  2830. // if(tableView==self.itemListTable)
  2831. // {
  2832. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2833. NSString *CellIdentifier;
  2834. #ifdef SCANNER_ORDER
  2835. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2836. CellIdentifier = @"ScanCartItemCell";
  2837. ScanCartItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2838. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2839. item_json = [self itemJsonAtIndexPath:indexPath];
  2840. NSString* notes = [item_json valueForKey:@"note"];
  2841. if(notes.length>0)
  2842. {
  2843. cell.labelNotes.text = notes;
  2844. }
  2845. else
  2846. {
  2847. cell.labelNotes.text = nil;
  2848. }
  2849. NSString* description =[item_json valueForKey:@"description"];
  2850. NSString* model =[item_json valueForKey:@"model"];
  2851. NSString* dimension =[item_json valueForKey:@"dimension"] ;
  2852. int count =[[item_json valueForKey:@"count"] intValue];
  2853. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  2854. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  2855. double discount=[[item_json valueForKey:@"discount"] doubleValue];
  2856. cell.discount = discount;
  2857. if(appDelegate.user_type == USER_ROLE_CUSTOMER)
  2858. {
  2859. cell.btnScanDiscount.hidden = true;
  2860. }
  2861. else
  2862. {
  2863. switch(RASingleton.sharedInstance.price_type)
  2864. {
  2865. case 0: cell.btnScanDiscount.hidden = true;
  2866. break;;
  2867. case 1:
  2868. {
  2869. if(![item_json[@"special_price"] boolValue]&&![item_json[@"net_price"] boolValue])
  2870. cell.btnScanDiscount.hidden = false;
  2871. else
  2872. cell.btnScanDiscount.hidden = true;
  2873. }
  2874. break;;
  2875. // case 2: pricename = @"25%";
  2876. // break;
  2877. }
  2878. }
  2879. NSString* product_id = [item_json valueForKey:@"product_id"];
  2880. CGRect frame = cell.frame;
  2881. cell.labelMpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  2882. __weak typeof(self) weakSelf = self;
  2883. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  2884. {
  2885. int result = [[ext objectForKey:@"result"] intValue];
  2886. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  2887. if (result == 2 && refresh) {
  2888. [self ReloadData];
  2889. return;
  2890. }
  2891. NSMutableDictionary * item_json = nil;
  2892. if (weakSelf.back_order_flag) {
  2893. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  2894. } else {
  2895. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  2896. }
  2897. // int count=[[item_json valueForKey:@"count"] intValue];
  2898. // if(count==qty)
  2899. // return;
  2900. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  2901. return ;
  2902. }
  2903. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  2904. double unit_cuft = [[item_json valueForKey:@"unit_cuft"] doubleValue];
  2905. [item_json setValue:[NSString stringWithFormat:@"%f",unit_cuft*qty] forKey:@"cuft"];
  2906. // [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  2907. // [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  2908. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  2909. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  2910. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty*(1-discount/100.0)] forKey:@"subtotal_price"];
  2911. if (weakSelf.back_order_flag) {
  2912. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  2913. } else {
  2914. weakSelf.content_arr[indexPath.row]= item_json;
  2915. }
  2916. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  2917. [weakSelf refresh_total];
  2918. #ifdef RA_NOTIFICATION
  2919. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  2920. #else
  2921. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2922. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  2923. #endif
  2924. };
  2925. // cell.delegate=self;
  2926. // cell.from=indexPath;
  2927. if(RASingleton.sharedInstance.price_type==1&&([item_json[@"net_price"] boolValue]||[item_json[@"special_price"] boolValue]||discount>0))
  2928. {
  2929. cell.labelUnitPrice.textColor= [UIColor redColor];
  2930. if([item_json[@"special_price"] boolValue]||discount>0)
  2931. {
  2932. cell.labelOldPrice.hidden = false;
  2933. // if([item_json[@"special_price"] boolValue])
  2934. // {
  2935. cell.labelOldPrice.text=[RAConvertor currencyNumber:[item_json[@"price1"] doubleValue]];//[NSString stringWithFormat:@"%.2f",[item_json[@"price1"] doubleValue]];
  2936. // }
  2937. // else
  2938. // {
  2939. // }
  2940. }
  2941. else
  2942. cell.labelOldPrice.hidden = true;
  2943. }
  2944. else
  2945. {
  2946. cell.labelUnitPrice.textColor= [UIColor blackColor];
  2947. cell.labelOldPrice.hidden = true;
  2948. }
  2949. // if(discount>0)
  2950. // {
  2951. // cell.labelNotes.text = [NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  2952. // cell.labelOldPrice.hidden = false;
  2953. //// cell.labelOldPrice.textColor = [UIColor redColor];
  2954. // cell.labelUnitPrice.textColor= [UIColor redColor];
  2955. // cell.labelOldPrice.text=[item_json[@"unit_price"] stringValue];
  2956. // frame.size.height = 120;
  2957. // }
  2958. // else
  2959. // {
  2960. //
  2961. //
  2962. // cell.labelOldPrice.hidden = true;
  2963. // cell.labelNotes.text = nil;
  2964. // frame.size.height = 94;
  2965. // }
  2966. cell.unit_price = unitprice;
  2967. // cell.labelAttribute.text = attribute;
  2968. // cell.labelCurrency.text = currency;
  2969. NSString* subtotal = [RAConvertor currencyNumber:unitprice*count*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*count*(1-discount/100)];
  2970. NSString* newunitprice = [RAConvertor currencyNumber:unitprice*(1-discount/100)];//[NSString stringWithFormat:@"%.2f",unitprice*(1-discount/100)];
  2971. cell.labelModel.text = model;
  2972. cell.labelDescription.text = [NSString stringWithFormat:@"%@\n%@",description,dimension];
  2973. // if(noprice&&unitprice==0.0)
  2974. // {
  2975. // cell.labelPrice.text = @"No Price";
  2976. //
  2977. // cell.labelUnitPrice.text = @"No Price";
  2978. // }
  2979. // else
  2980. {
  2981. cell.labelSubtotal.text = subtotal;
  2982. cell.labelUnitPrice.text = newunitprice;
  2983. }
  2984. bool check = [[item_json valueForKey:@"check"] boolValue];
  2985. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  2986. cell.cart_id = cart_item_id;
  2987. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  2988. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  2989. // else
  2990. // [cell init_Stepper:1 max:9999 min:1 value:count];
  2991. [cell set_Count:count];
  2992. // Button 设置了大小约束,Size就不会随内容变化
  2993. cell.backgroundColor = [UIColor whiteColor];
  2994. return cell;
  2995. #else
  2996. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2997. CellIdentifier = @"CartItemCell";
  2998. ModelItemCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  2999. NSDictionary * item_json = nil;//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3000. if (self.back_order_flag) {
  3001. item_json = [self itemJsonAtIndexPath:indexPath];
  3002. } else {
  3003. item_json = self.content_arr[indexPath.row];
  3004. }
  3005. NSDictionary * combine_json =[item_json objectForKey:@"combine"];
  3006. NSDictionary * master_json = [item_json objectForKey:@"combine_master"];
  3007. if (cell.masterBtn != nil) {
  3008. if (master_json == nil) {
  3009. cell.masterBtn.hidden = YES;
  3010. } else{
  3011. cell.masterBtn.hidden = NO;
  3012. cell.master_items = master_json;
  3013. }
  3014. }
  3015. bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3016. NSString* notes = [item_json valueForKey:@"note"];
  3017. BOOL is_out_of_stock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  3018. bool noprice =[[item_json valueForKey:@"is_no_price"]boolValue];
  3019. cell.noprice = noprice;
  3020. cell.enable_longpress = true;
  3021. cell.bundle_item=combine_json;
  3022. NSString* img_url = [item_json valueForKey:@"img_url"];
  3023. NSString* description = [item_json valueForKey:@"description"];
  3024. // NSString* identifier = [item_json valueForKey:@"identifier"];
  3025. // NSString* attribute = [item_json valueForKey:@"attribute"];
  3026. // NSString* currency = [item_json valueForKey:@"currency"];
  3027. int count =[[item_json valueForKey:@"count"] intValue];
  3028. int stockUom =[[item_json valueForKey:@"stockUom"] intValue];
  3029. // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3030. double unitprice=[[item_json valueForKey:@"unit_price"] doubleValue];
  3031. double discount =[[item_json valueForKey:@"discount"] doubleValue];
  3032. NSString* product_id = [item_json valueForKey:@"product_id"];
  3033. // handle no such model
  3034. if(product_id.length==0)
  3035. cell.labelNoSuchModel.hidden=false;
  3036. else
  3037. cell.labelNoSuchModel.hidden=true;
  3038. //if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  3039. if (!is_out_of_stock) {
  3040. cell.labelOutOfStock.hidden = YES;
  3041. } else {
  3042. cell.labelOutOfStock.hidden = NO;
  3043. }
  3044. // } else {
  3045. // cell.labelOutOfStock.hidden = YES;
  3046. // }
  3047. // discount = 5.0;
  3048. cell.discount = discount;
  3049. CGRect frame = cell.frame;
  3050. if(notes.length>0)
  3051. {
  3052. cell.labelNotes.text = [@"Note: " stringByAppendingString:[notes stringByReplacingOccurrencesOfString:@"\n" withString:@" "]];
  3053. frame.size.height = 146;
  3054. }
  3055. else
  3056. {
  3057. cell.labelNotes.text = nil;
  3058. frame.size.height = 120;
  3059. }
  3060. // cell.frame = frame;
  3061. NSString* discountstr=[NSString stringWithFormat:@"%@%% off", [RAUtils FloatFormat:discount]];
  3062. if(isfree)
  3063. {
  3064. cell.labelOldPrice.hidden = false;
  3065. cell.labelOldPrice.textColor = [UIColor redColor];
  3066. cell.labelOldPrice.text=@"Free";
  3067. cell.labelOldPrice.hideline = true;
  3068. cell.labelDiscount.hidden = true;
  3069. }
  3070. else
  3071. {
  3072. cell.labelOldPrice.textColor = [UIColor blackColor];
  3073. cell.labelOldPrice.hideline = false;
  3074. if(discount==0)
  3075. {
  3076. cell.labelOldPrice.hidden = true;
  3077. cell.labelDiscount.hidden = true;
  3078. }
  3079. else
  3080. {
  3081. cell.labelOldPrice.hidden = false;
  3082. cell.labelDiscount.hidden = false;
  3083. }
  3084. }
  3085. __weak typeof(self) weakSelf = self;
  3086. cell.onReturnQTY=^(int qty,NSDictionary* ext)
  3087. {
  3088. int result = [[ext objectForKey:@"result"] intValue];
  3089. BOOL refresh = [[ext objectForKey:@"refresh"] boolValue];
  3090. if (result == 2 && refresh) {
  3091. [self ReloadData];
  3092. return;
  3093. }
  3094. NSMutableDictionary * item_json = nil;
  3095. if (weakSelf.back_order_flag) {
  3096. item_json = [[weakSelf itemJsonAtIndexPath:indexPath] mutableCopy];
  3097. } else {
  3098. item_json = [weakSelf.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3099. }
  3100. // int count=[[item_json valueForKey:@"count"] intValue];
  3101. // if(count==qty)
  3102. // return;
  3103. if ([[ext valueForKey:@"result"] integerValue] == 8) {
  3104. return ;
  3105. }
  3106. [item_json setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"count"];
  3107. [item_json setValue:[ext valueForKey:@"cuft"] forKey:@"cuft"];
  3108. [item_json setValue:[ext valueForKey:@"carton"] forKey:@"carton"];
  3109. [item_json setValue:[ext valueForKey:@"weight"] forKey:@"weight"];
  3110. double unit_price = [[item_json valueForKey:@"unit_price"] doubleValue];
  3111. // double sub_total=[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3112. [item_json setValue:[NSString stringWithFormat:@"%f",unit_price*qty] forKey:@"subtotal_price"];
  3113. if (weakSelf.back_order_flag) {
  3114. [weakSelf updateItemJson:item_json atIndexPath:indexPath];
  3115. } else {
  3116. weakSelf.content_arr[indexPath.row]= item_json;
  3117. }
  3118. // [self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3119. [weakSelf refresh_total];
  3120. #ifdef RA_NOTIFICATION
  3121. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3122. #else
  3123. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3124. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3125. #endif
  3126. };
  3127. // cell.delegate=self;
  3128. // cell.from=indexPath;
  3129. cell.unit_price = unitprice;
  3130. // cell.labelAttribute.text = attribute;
  3131. // cell.labelCurrency.text = currency;
  3132. NSString* oldprice =[NSString stringWithFormat:@"%.2f",unitprice];
  3133. NSString* newprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)*count];
  3134. NSString* newunitprice = [NSString stringWithFormat:@"%.2f",unitprice* (1.0-discount/100)];
  3135. if(appDelegate.can_see_price&&appDelegate.price_hidden==false)
  3136. {
  3137. }
  3138. else
  3139. {
  3140. oldprice=nil;
  3141. newprice=nil;
  3142. newunitprice=nil;
  3143. }
  3144. cell.labelDiscount.text = discountstr;
  3145. cell.labelOldPrice.text = oldprice;
  3146. cell.labelMasterpack.text =[NSString stringWithFormat:@"Sold in QTY of:%d", stockUom];
  3147. cell.labelDescription.text = description;
  3148. // cell.labelIdentifier.text = identifier;
  3149. if(noprice&&unitprice==0.0)
  3150. {
  3151. cell.labelPrice.text = @"No Price";
  3152. cell.labelUnitPrice.text = @"No Price";
  3153. }
  3154. else
  3155. {
  3156. cell.labelPrice.text = newprice;
  3157. cell.labelUnitPrice.text = newunitprice;
  3158. }
  3159. bool check = [[item_json valueForKey:@"check"] boolValue];
  3160. if(check)
  3161. {
  3162. cell.img_checkmark.hidden=false;
  3163. // [item_json setValue:@"0" forKey:@"check"];
  3164. }
  3165. else
  3166. {
  3167. // [item_json setValue:@"1" forKey:@"check"];
  3168. cell.img_checkmark.hidden=true;
  3169. }
  3170. NSString* cart_item_id= [item_json valueForKey:@"cart_item_id"];
  3171. cell.cart_id = cart_item_id;
  3172. if(/*appDelegate.user_type==USER_ROLE_CUSTOMER*/ true)
  3173. {
  3174. #ifdef IGNORE_MPACK
  3175. [cell init_Stepper:1 max:9999 min:1 value:count];
  3176. #else
  3177. [cell init_Stepper:stockUom max:9999 min:stockUom value:count];
  3178. #endif
  3179. }
  3180. // else
  3181. // [cell init_Stepper:1 max:9999 min:1 value:count];
  3182. [cell set_Count:count];
  3183. // Button 设置了大小约束,Size就不会随内容变化
  3184. [cell.btnImage setContentMode:UIViewContentModeScaleAspectFit];
  3185. [cell.btnImage setContentEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
  3186. [cell.btnImage setContentHorizontalAlignment:UIControlContentHorizontalAlignmentFill];
  3187. [cell.btnImage setContentVerticalAlignment:UIControlContentVerticalAlignmentFill];
  3188. cell.btnImage.imageView.contentMode = UIViewContentModeScaleAspectFit;
  3189. if (![cell.imageName isEqualToString:img_url]) {
  3190. cell.imageName = img_url;
  3191. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  3192. [cell.btnImage setImage:[UIImage imageNamed:@"loading_s"] forState:UIControlStateNormal];
  3193. NSString* file_name=[img_url lastPathComponent];
  3194. NSData* img_data=[iSalesDB load_cached_img:file_name loadFrom:img_url];
  3195. if(img_data!=nil)
  3196. {
  3197. UIImage * img =[UIImage imageWithData:img_data];
  3198. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3199. [cell.btnImage setImage:img forState:UIControlStateNormal];
  3200. }
  3201. else
  3202. {
  3203. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3204. NSData* downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
  3205. dispatch_async(dispatch_get_main_queue(), ^{
  3206. if(downloadimg_data!=nil)
  3207. {
  3208. [iSalesDB cache_img:downloadimg_data filename:file_name saveTo:img_url];
  3209. UIImage * img =[UIImage imageWithData:downloadimg_data];
  3210. // [cell.btnImage setBackgroundImage:img forState:UIControlStateNormal];
  3211. [cell.btnImage setImage:img forState:UIControlStateNormal];
  3212. }
  3213. else
  3214. {
  3215. // [cell.btnImage setBackgroundImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  3216. [cell.btnImage setImage:[UIImage imageNamed:@"notfound_s"] forState:UIControlStateNormal];
  3217. }
  3218. });
  3219. });
  3220. }
  3221. }
  3222. cell.backgroundColor = [UIColor whiteColor];
  3223. if(self.itemListTable.editing)
  3224. {
  3225. cell.editCount.enabled = false;
  3226. cell.stepper.hidden=true;
  3227. }
  3228. else
  3229. {
  3230. cell.editCount.enabled=true;
  3231. cell.stepper.hidden=false;
  3232. }
  3233. return cell;
  3234. // }
  3235. // else
  3236. // {
  3237. // NSString *CellIdentifier = @"OrderInfoListItem";
  3238. // UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  3239. // return cell;
  3240. // }
  3241. #endif
  3242. }
  3243. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  3244. {
  3245. if(!self.itemListTable.editing)
  3246. return;
  3247. // NSMutableDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3248. NSMutableDictionary * item_json = nil;
  3249. if (self.back_order_flag) {
  3250. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3251. } else {
  3252. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3253. }
  3254. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3255. if ([self.edit_select_arr containsObject:cart_item_id])
  3256. {
  3257. [self.edit_select_arr removeObject:cart_item_id];
  3258. }
  3259. }
  3260. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3261. {
  3262. #ifdef SCANNER_ORDER
  3263. return;
  3264. #endif
  3265. NSMutableDictionary * item_json = nil;
  3266. if (self.back_order_flag) {
  3267. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3268. } else {
  3269. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3270. }
  3271. // NSMutableDictionary * item_json =[self.content_arr[indexPath.row] mutableCopy];// [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3272. if(self.itemListTable.editing)
  3273. {
  3274. NSString *cart_item_id=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3275. if (![self.edit_select_arr containsObject:cart_item_id]) {
  3276. [self.edit_select_arr addObject:cart_item_id];
  3277. }
  3278. return;
  3279. }
  3280. // no checkmark support anymore for cart
  3281. return;
  3282. // ModelItemCell* cell = (ModelItemCell*)[tableView cellForRowAtIndexPath:indexPath];
  3283. //
  3284. //
  3285. // cell.selected = false;
  3286. // // self.dirty = true;
  3287. //
  3288. //
  3289. // bool check = [[item_json valueForKey:@"check"] boolValue];
  3290. // if(check)
  3291. // {
  3292. // [item_json setValue:@"false" forKey:@"check"];
  3293. // cell.img_checkmark.hidden=true;
  3294. // [self.btnselect setTitle: @"Select all" forState: UIControlStateNormal];
  3295. // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3296. // // self.total-=totalprice;
  3297. // }
  3298. // else
  3299. // {
  3300. // [item_json setValue:@"true" forKey:@"check"];
  3301. // cell.img_checkmark.hidden=false;
  3302. // // double totalprice =[[item_json valueForKey:@"subtotal_price"] doubleValue];
  3303. // // self.total+=totalprice;
  3304. // }
  3305. //
  3306. //
  3307. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3308. //
  3309. //
  3310. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3311. //
  3312. // NSDictionary* check_json = [iSalesNetwork cart_check:ids];
  3313. //
  3314. // dispatch_async(dispatch_get_main_queue(), ^{
  3315. //
  3316. //
  3317. //
  3318. // if([[check_json valueForKey:@"result"] intValue]==2)
  3319. // {
  3320. //
  3321. //
  3322. // if([item_json[@"check"] boolValue]==false)
  3323. // item_json[@"check"]= @"false";
  3324. // else
  3325. // item_json[@"check"]= @"true";
  3326. //
  3327. // self.content_arr[indexPath.row] = item_json;
  3328. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3329. //
  3330. //
  3331. // [self reload_container_getdata:false];
  3332. //
  3333. //
  3334. // }
  3335. // else
  3336. // {
  3337. // [RAUtils message_alert:[check_json valueForKey:@"err_msg"] title:nil controller:self] ;
  3338. // }
  3339. //
  3340. //
  3341. //
  3342. // });
  3343. // });
  3344. //
  3345. // //debug
  3346. // //[self.content_data setObject:item_json forKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3347. //
  3348. // [self refresh_total];
  3349. //self.labelTotal.text=[NSString stringWithFormat:@"$%.2f",self.total];
  3350. }
  3351. - (UITableViewCellEditingStyle)tableView:(UITableView *)tv editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
  3352. if(self.itemListTable.editing)
  3353. return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
  3354. else
  3355. return UITableViewCellEditingStyleDelete;
  3356. }
  3357. #pragma mark 在滑动手势删除某一行的时候,显示出更多的按钮
  3358. - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
  3359. {
  3360. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3361. // 添加一个删除按钮
  3362. self.indexPath=indexPath;
  3363. NSMutableDictionary * item_json = nil;
  3364. if (self.back_order_flag) {
  3365. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3366. } else {
  3367. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3368. }
  3369. NSString* productID = [item_json valueForKey:@"product_id"];
  3370. BOOL outOfStock = [[item_json valueForKey:@"is_out_of_stock"] boolValue];
  3371. __weak typeof(self) weakself = self;
  3372. UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@" Delete " handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3373. DebugLog(@"delete click");
  3374. //[self.itemListTable setEditing:false animated:YES];
  3375. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Confirm Deletion" message:@"Are you sure to delete this model?" preferredStyle:UIAlertControllerStyleAlert];
  3376. UIAlertAction *action_2 = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3377. // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3378. NSMutableDictionary * item_json = nil;
  3379. if (self.back_order_flag) {
  3380. item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  3381. } else {
  3382. item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3383. }
  3384. NSString *ids=[NSString stringWithFormat:@"%@",[item_json valueForKey:@"cart_item_id"] ];
  3385. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Remove Model" completion:^{
  3386. [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  3387. NSMutableDictionary* cart_json = result;
  3388. [waitalert dismissViewControllerAnimated:YES completion:^{
  3389. if([[cart_json valueForKey:@"result"] intValue]==2)
  3390. {
  3391. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3392. if (self.back_order_flag) {
  3393. NSInteger section_count = [self sectionCount];
  3394. for (int i = 0; i < section_count; i++) {
  3395. NSInteger item_count = [self itemCountInSection:i];
  3396. BOOL ready_break = NO;
  3397. for (int j = 0; j < item_count; j++) {
  3398. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3399. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3400. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3401. if([_id isEqualToString:ids])
  3402. {
  3403. [self updateItemJson:nil atIndexPath:indexPath];
  3404. ready_break = YES;
  3405. break;
  3406. }
  3407. }
  3408. if (ready_break) {
  3409. break;
  3410. }
  3411. }
  3412. } else {
  3413. for(int i=0;i<self.content_arr.count;i++)
  3414. {
  3415. NSDictionary* obj_json = self.content_arr[i];
  3416. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3417. if([_id isEqualToString:ids])
  3418. {
  3419. [self.content_arr removeObjectAtIndex:i];
  3420. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3421. break;
  3422. // appDelegate.cart_count--;
  3423. // [appDelegate update_count_mark];
  3424. }
  3425. }
  3426. }
  3427. #ifdef SCANNER_ORDER
  3428. self.cart_json = cart_json;
  3429. #endif
  3430. [self.itemListTable reloadData];
  3431. [self refresh_total];
  3432. #ifdef RA_NOTIFICATION
  3433. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3434. #else
  3435. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3436. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3437. #endif
  3438. // [self reload_data];
  3439. }
  3440. else
  3441. {
  3442. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  3443. }
  3444. }];
  3445. }];
  3446. }];
  3447. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3448. //
  3449. // NSDictionary* cart_json = [RANetwork cart_remove:ids];
  3450. //
  3451. // dispatch_async(dispatch_get_main_queue(), ^{
  3452. //
  3453. //
  3454. //
  3455. // if([[cart_json valueForKey:@"result"] intValue]==2)
  3456. // {
  3457. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3458. // if (self.back_order_flag) {
  3459. //
  3460. // NSInteger section_count = [self sectionCount];
  3461. // for (int i = 0; i < section_count; i++) {
  3462. // NSInteger item_count = [self itemCountInSection:i];
  3463. // BOOL ready_break = NO;
  3464. //
  3465. // for (int j = 0; j < item_count; j++) {
  3466. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  3467. // NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  3468. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3469. // if([_id isEqualToString:ids])
  3470. // {
  3471. // [self updateItemJson:nil atIndexPath:indexPath];
  3472. // ready_break = YES;
  3473. // break;
  3474. // }
  3475. // }
  3476. //
  3477. // if (ready_break) {
  3478. // break;
  3479. // }
  3480. // }
  3481. //
  3482. // } else {
  3483. // for(int i=0;i<self.content_arr.count;i++)
  3484. // {
  3485. // NSDictionary* obj_json = self.content_arr[i];
  3486. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3487. // if([_id isEqualToString:ids])
  3488. // {
  3489. // [self.content_arr removeObjectAtIndex:i];
  3490. // // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3491. // break;
  3492. // // appDelegate.cart_count--;
  3493. // // [appDelegate update_count_mark];
  3494. // }
  3495. //
  3496. // }
  3497. // }
  3498. // [self.itemListTable reloadData];
  3499. // [self refresh_total];
  3500. // #ifdef RA_NOTIFICATION
  3501. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3502. // #else
  3503. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3504. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3505. // #endif
  3506. // // [self reload_data];
  3507. // }
  3508. // else
  3509. // {
  3510. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  3511. // }
  3512. //
  3513. // });
  3514. // });
  3515. }];
  3516. UIAlertAction *action_3 = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3517. }];
  3518. [alertController addAction:action_2];
  3519. [alertController addAction:action_3];
  3520. [self presentViewController:alertController animated:YES completion:nil];
  3521. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Delete confirm", nil) message:NSLocalizedString(@"Are you sure remove model from cart?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3522. // alert.tag = ALERT_DEL;
  3523. // // alert.
  3524. // [alert show];
  3525. }];
  3526. deleteRowAction.backgroundColor = [UIColor redColor];
  3527. UITableViewRowAction *notifyMeAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Notify Me" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  3528. {
  3529. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  3530. [RANetwork request_notifymodel:productID emailAddr:nil withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  3531. NSMutableDictionary *dic = result;
  3532. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3533. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  3534. int result_code = [[dic valueForKey:@"result"] intValue];
  3535. if (result_code != RESULT_TRUE && result_code != RESULT_NO_EMAIL_ADDRESS)
  3536. {
  3537. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3538. if ([dic valueForKey:@"err_msg"]) {
  3539. msg = [dic valueForKey:@"err_msg"];
  3540. }
  3541. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3542. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3543. }];
  3544. [errorAlertVC addAction:action];
  3545. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3546. } else if (result_code == RESULT_TRUE){
  3547. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  3548. } else if (result_code == RESULT_NO_EMAIL_ADDRESS) {
  3549. [weakself showAddressBoxToEmailProduct:productID];
  3550. }
  3551. }];
  3552. }];
  3553. }];
  3554. // dispatch_async(dispatch_get_global_queue(0,0), ^{
  3555. //
  3556. // NSDictionary *dic = [RANetwork notifyModel:productID emailAddr:nil withScreen:ScreenCodeCart];
  3557. //
  3558. // dispatch_async(dispatch_get_main_queue(), ^{
  3559. //
  3560. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  3561. //
  3562. // NSInteger result = [[dic valueForKey:@"result"] integerValue];
  3563. //
  3564. // if (result != RESULT_TRUE && result != RESULT_NO_EMAIL_ADDRESS) {
  3565. //
  3566. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  3567. //
  3568. // if ([dic valueForKey:@"err_msg"]) {
  3569. // msg = [dic valueForKey:@"err_msg"];
  3570. // }
  3571. //
  3572. //
  3573. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  3574. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  3575. //
  3576. // }];
  3577. //
  3578. // [errorAlertVC addAction:action];
  3579. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  3580. //
  3581. // } else if (result == RESULT_TRUE){
  3582. //
  3583. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  3584. //
  3585. // } else if (result == RESULT_NO_EMAIL_ADDRESS) {
  3586. //
  3587. // [weakself showAddressBoxToEmailProduct:productID];
  3588. //
  3589. // }
  3590. // });
  3591. //
  3592. //
  3593. // });
  3594. };
  3595. }];
  3596. notifyMeAction.backgroundColor = UIColorFromRGB(0x9BBF5A);
  3597. UITableViewRowAction *addWatchAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Move To Wish List" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3598. DebugLog(@"Wishlist click");
  3599. NSMutableDictionary * item_json = nil;
  3600. if (self.back_order_flag) {
  3601. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3602. } else {
  3603. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3604. }
  3605. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  3606. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3607. [RANetwork request_move_cart2wish:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  3608. NSDictionary* return_json = result;
  3609. if([[return_json valueForKey:@"result"] intValue]==2)
  3610. {
  3611. #ifdef RA_NOTIFICATION
  3612. [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3613. #else
  3614. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3615. [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3616. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3617. #endif
  3618. for(int i=0;i<self.content_arr.count;i++)
  3619. {
  3620. NSDictionary* obj_json = self.content_arr[i];
  3621. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3622. if([_id isEqualToString:cart_item_id])
  3623. {
  3624. if (self.back_order_flag) {
  3625. [self updateItemJson:nil atIndexPath:indexPath];
  3626. } else {
  3627. [self.content_arr removeObjectAtIndex:i];
  3628. }
  3629. [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3630. appDelegate.cart_count--;
  3631. [appDelegate update_count_mark];
  3632. [self refresh_total];
  3633. }
  3634. }
  3635. [self.itemListTable reloadData];
  3636. }
  3637. else
  3638. {
  3639. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  3640. }
  3641. }];
  3642. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3643. //// ModelItemCell* cell=[self.itemListTable cellForRowAtIndexPath:indexPath];
  3644. //// [cell cancel_setQTY];
  3645. //
  3646. // NSDictionary* return_json = [RANetwork move_cart2wish:cart_item_id ];
  3647. //
  3648. // dispatch_async(dispatch_get_main_queue(), ^{
  3649. //
  3650. // if([[return_json valueForKey:@"result"] intValue]==2)
  3651. // {
  3652. //
  3653. //
  3654. //
  3655. //
  3656. //
  3657. //
  3658. //#ifdef RA_NOTIFICATION
  3659. // [ActiveViewController Notify:@"WatchListViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3660. //#else
  3661. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3662. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  3663. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3664. //
  3665. //#endif
  3666. //
  3667. //
  3668. // for(int i=0;i<self.content_arr.count;i++)
  3669. // {
  3670. // NSDictionary* obj_json = self.content_arr[i];
  3671. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  3672. // if([_id isEqualToString:cart_item_id])
  3673. // {
  3674. // if (self.back_order_flag) {
  3675. // [self updateItemJson:nil atIndexPath:indexPath];
  3676. // } else {
  3677. // [self.content_arr removeObjectAtIndex:i];
  3678. // }
  3679. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  3680. // appDelegate.cart_count--;
  3681. // [appDelegate update_count_mark];
  3682. //
  3683. //
  3684. // [self refresh_total];
  3685. // }
  3686. //
  3687. // }
  3688. //
  3689. // [self.itemListTable reloadData];
  3690. //
  3691. // }
  3692. // else
  3693. // {
  3694. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Wish List" controller:self] ;
  3695. // }
  3696. //
  3697. //
  3698. //
  3699. // });
  3700. // });
  3701. }];
  3702. addWatchAction.backgroundColor = UIColorFromRGB(0x339966);
  3703. // 添加一个编辑按钮
  3704. UITableViewRowAction *editRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit Price"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3705. DebugLog(@"edit click");
  3706. if (appDelegate.user_type == USER_ROLE_CUSTOMER && appDelegate.customer_type == CustomerTypeStore) {
  3707. if (self.currentOrderIsMerged) { // 合并过的订单不能编辑价格
  3708. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Purchase Order Can't Edit Price" preferredStyle:UIAlertControllerStyleAlert];
  3709. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3710. [alert dismissViewControllerAnimated:YES completion:nil];
  3711. }];
  3712. [alert addAction:action];
  3713. if (weakself) {
  3714. __strong typeof(weakself) strongself = weakself;
  3715. [strongself presentViewController:alert animated:YES completion:nil];
  3716. }
  3717. return ;
  3718. }
  3719. if ([RASingleton sharedInstance].npd_shop_price_type == 0) { // 提货价不能编辑价格
  3720. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Current Price Type is %@,You Can't Change it",[RASingleton sharedInstance].deliveryString] preferredStyle:UIAlertControllerStyleAlert];
  3721. UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  3722. [alert dismissViewControllerAnimated:YES completion:nil];
  3723. }];
  3724. [alert addAction:action];
  3725. if (weakself) {
  3726. __strong typeof(weakself) strongself = weakself;
  3727. [strongself presentViewController:alert animated:YES completion:nil];
  3728. }
  3729. return ;
  3730. }
  3731. }
  3732. UIViewController* parentvc=self;
  3733. EditModelPriceViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"EditModelPriceViewController"];
  3734. NSMutableDictionary * item_json = nil;
  3735. if (self.back_order_flag) {
  3736. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3737. } else {
  3738. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3739. }
  3740. vc.discount=[[item_json valueForKey:@"discount"] floatValue];
  3741. vc.price = [[item_json valueForKey:@"unit_price"] floatValue];
  3742. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3743. __block NSString* cartid=[item_json valueForKey:@"cart_item_id"];
  3744. // vc.delegate = parentvc.self;
  3745. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  3746. vc.onSetValue = ^(double price,double discount){
  3747. bool bmodify=false;
  3748. if(price!= [[item_json valueForKey:@"unit_price"] floatValue])
  3749. bmodify=true;
  3750. NSString* notes = [item_json valueForKey:@"note"];
  3751. if(notes.length==0)
  3752. notes=@"";
  3753. if(bmodify)
  3754. {
  3755. if([notes isEqualToString:@""])
  3756. notes=@"PRICE MODIFIED";
  3757. NSRange range;
  3758. range = [notes rangeOfString:@"PRICE MODIFIED"];
  3759. if (range.location != NSNotFound) {
  3760. }else{
  3761. notes= [notes stringByAppendingString:@"\nPRICE MODIFIED"];
  3762. }
  3763. }
  3764. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Update Price" completion:^{
  3765. [RANetwork request_update_cart_modelprice:cartid price:price discount:discount notes:notes completionHandler:^(NSMutableDictionary *result) {
  3766. NSDictionary* cart_json = result;
  3767. [waitalert dismissViewControllerAnimated:YES completion:^{
  3768. if([[cart_json valueForKey:@"result"] intValue]==2)
  3769. {
  3770. [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  3771. [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  3772. [item_json setValue:notes forKey:@"note"];
  3773. if (self.back_order_flag) {
  3774. [self updateItemJson:item_json atIndexPath:indexPath];
  3775. } else {
  3776. self.content_arr[indexPath.row ] = item_json;
  3777. }
  3778. tableView.editing = false;
  3779. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3780. // [self refresh_total];
  3781. [weakself reload_data];
  3782. #ifdef RA_NOTIFICATION
  3783. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3784. #else
  3785. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3786. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3787. #endif
  3788. }
  3789. else
  3790. {
  3791. [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  3792. }
  3793. }];
  3794. }];
  3795. }];
  3796. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3797. //
  3798. //
  3799. //
  3800. // NSDictionary* cart_json = nil;
  3801. //
  3802. // cart_json = [RANetwork cart_setPrice:[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]] price:price discount:discount notes:notes];
  3803. //
  3804. // dispatch_async(dispatch_get_main_queue(), ^{
  3805. //
  3806. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3807. //
  3808. // if([[cart_json valueForKey:@"result"] intValue]==2)
  3809. // {
  3810. // [item_json setValue:[NSNumber numberWithDouble:price ] forKey:@"unit_price"];
  3811. //
  3812. // [item_json setValue:[NSNumber numberWithDouble:discount ] forKey:@"discount"];
  3813. // [item_json setValue:notes forKey:@"note"];
  3814. // if (self.back_order_flag) {
  3815. // [self updateItemJson:item_json atIndexPath:indexPath];
  3816. // } else {
  3817. // self.content_arr[indexPath.row ] = item_json;
  3818. // }
  3819. // tableView.editing = false;
  3820. //// [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3821. //// [self refresh_total];
  3822. //
  3823. //
  3824. // [weakself reload_data];
  3825. //
  3826. //#ifdef RA_NOTIFICATION
  3827. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  3828. //#else
  3829. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3830. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  3831. //#endif
  3832. // }
  3833. // else
  3834. // {
  3835. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Update Price" controller:self] ;
  3836. // }
  3837. //
  3838. //
  3839. //
  3840. //
  3841. // });
  3842. // });
  3843. // [self reload_data];//[main_vc checklogin:true];
  3844. };
  3845. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  3846. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  3847. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3848. [parentvc presentViewController:navi animated:YES completion:^{
  3849. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  3850. DebugLog(@"EditModelPriceViewController present.........");
  3851. // self.btop = false;
  3852. // <#code#>
  3853. }];
  3854. // [self.itemListTable setEditing:false animated:YES];
  3855. //[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3856. }];
  3857. editRowAction.backgroundColor = UIColorFromRGB(0xff9933);
  3858. // // 添加一个更多按钮
  3859. //
  3860. // UITableViewRowAction *moreRowAction = [UITableView RowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3861. //
  3862. // DebugLog(@点击了更多);
  3863. //
  3864. //
  3865. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3866. //
  3867. // }];
  3868. //
  3869. // moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark];
  3870. //
  3871. // 将设置好的按钮放到数组中返回
  3872. // UITableViewRowAction *freeRowAction = nil;
  3873. //
  3874. //
  3875. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3876. //
  3877. // bool isfree = [[item_json valueForKey:@"is_free"]boolValue];
  3878. //
  3879. // if(!isfree)
  3880. // {
  3881. //
  3882. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Set Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3883. //
  3884. // DebugLog(@"free click");
  3885. //
  3886. //
  3887. //
  3888. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Free give away confirm", nil) message:NSLocalizedString(@"Are you sure make this model free?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3889. // alert.tag = ALERT_SET_FREE;
  3890. // // alert.
  3891. // [alert show];
  3892. // }];
  3893. // }
  3894. // else
  3895. // {
  3896. //
  3897. // freeRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Not Free" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3898. //
  3899. // UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Restore free model confirm", nil) message:NSLocalizedString(@"Are you sure restore free model?", nil) delegate:self cancelButtonTitle:NSLocalizedString(@"NO", nil) otherButtonTitles:NSLocalizedString(@"YES", nil), nil];
  3900. // alert.tag = ALERT_RESTORE_FREE;
  3901. // // alert.
  3902. // [alert show];
  3903. // }];
  3904. // }
  3905. //
  3906. //
  3907. //
  3908. // freeRowAction.backgroundColor = [UIColor lightGrayColor];
  3909. UITableViewRowAction *noteRowAction = nil;
  3910. // NSDictionary * item_json = [self.content_arr[indexPath.row] mutableCopy];//[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]];
  3911. noteRowAction=[UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Edit note" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
  3912. DebugLog(@"item note click");
  3913. UIViewController* parentvc=self;
  3914. ItemNotesViewController * vc =[[UIStoryboard storyboardWithName:@"ERP_Mobile_Cart" bundle:nil] instantiateViewControllerWithIdentifier:@"ItemNotesViewController"];
  3915. NSMutableDictionary * item_json = nil;
  3916. if (self.back_order_flag) {
  3917. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3918. } else {
  3919. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3920. }
  3921. vc.onSaveNote=^(NSString* notes){
  3922. [item_json setValue:notes forKey:@"note"];
  3923. if (self.back_order_flag) {
  3924. [self updateItemJson:item_json atIndexPath:indexPath];
  3925. } else {
  3926. self.content_arr[indexPath.row ] = item_json;
  3927. }
  3928. tableView.editing = false;
  3929. [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3930. };
  3931. vc.notes=[item_json valueForKey:@"note"];
  3932. vc.cart_id = [item_json valueForKey:@"cart_item_id"];//[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  3933. // vc.delegate = parentvc.self;
  3934. // loginvc.modalPresentationStyle = UIModalPresentationFormSheet;//有三种状态,自己看看是哪种
  3935. // vc.onSetValue = ^(){
  3936. // [self reload_data];//[main_vc checklogin:true];
  3937. // };
  3938. //
  3939. UINavigationController* navi = [[UINavigationController alloc] initWithRootViewController:vc] ;
  3940. // [self hackModalSheetSize:CGSizeMake(450, 200) ofVC:navi];
  3941. navi.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;//有三种状态,自己看看是哪种
  3942. [parentvc presentViewController:navi animated:YES completion:^{
  3943. // navi.view.superview.bounds = CGRectMake(0, 0, 480, 320);
  3944. DebugLog(@"EditModelPriceViewController present.........");
  3945. // self.btop = false;
  3946. // <#code#>
  3947. }];
  3948. // [self.itemListTable setEditing:false animated:YES];
  3949. // [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  3950. }];
  3951. noteRowAction.backgroundColor = [UIColor lightGrayColor];
  3952. UITableViewRowAction *move2BackAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Move to Back Order" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  3953. NSDictionary *item_json = [self itemJsonAtIndexPath:indexPath];
  3954. NSString* cart_item_id = [item_json valueForKey:@"cart_item_id"];
  3955. __block UIAlertController * waitalert = [RAUtils waiting_alert:self title:@"Move To Back Order" completion:^{
  3956. [RANetwork request_movetobackorder:cart_item_id completionHandler:^(NSMutableDictionary *result) {
  3957. NSMutableDictionary* return_json =result ;
  3958. [waitalert dismissViewControllerAnimated:YES completion:^{
  3959. if([[return_json valueForKey:@"result"] intValue]==2) {
  3960. [self reload_data];
  3961. } // if 2
  3962. else {
  3963. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Back Order" controller:self] ;
  3964. }
  3965. }];
  3966. }];
  3967. }];
  3968. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  3969. //
  3970. // NSDictionary* return_json = [RANetwork movetobackorder:cart_item_id];
  3971. //
  3972. // dispatch_async(dispatch_get_main_queue(), ^{
  3973. //
  3974. // [waitalert dismissViewControllerAnimated:YES completion:nil];
  3975. //
  3976. // if([[return_json valueForKey:@"result"] intValue]==2) {
  3977. //
  3978. // [self reload_data];
  3979. //
  3980. // } // if 2
  3981. // else {
  3982. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Move To Back Order" controller:self] ;
  3983. // }
  3984. //
  3985. // }); // main
  3986. //
  3987. // }); // global
  3988. }];
  3989. move2BackAction.backgroundColor = UIColorFromRGB(0x336699);
  3990. if(appDelegate.user_type==USER_ROLE_EMPLOYEE)
  3991. {
  3992. NSMutableDictionary * item_json = nil;
  3993. if (self.back_order_flag) {
  3994. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  3995. } else {
  3996. item_json = [self.content_arr[indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  3997. }
  3998. NSString* product_id = [item_json valueForKey:@"product_id"];
  3999. int is_rate = [item_json[@"is_rate"] intValue];
  4000. NSMutableArray* arr=[@[] mutableCopy];
  4001. BOOL condition = outOfStock;
  4002. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)|| defined (BUILD_CONTRAST)
  4003. #ifdef OFFLINE_MODE
  4004. condition = !appDelegate.offline_mode && outOfStock;
  4005. #endif
  4006. if (condition) {
  4007. [arr addObject:notifyMeAction];
  4008. }
  4009. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  4010. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  4011. if (self.back_order_flag && available) {
  4012. [arr addObject:move2BackAction];
  4013. }
  4014. #endif
  4015. #if defined(BUILD_HOMER) || defined(BUILD_GATIT)
  4016. #ifdef OFFLINE_MODE
  4017. condition = !appDelegate.offline_mode && outOfStock;
  4018. #endif
  4019. if (condition) {
  4020. [arr addObject:notifyMeAction];
  4021. }
  4022. #endif
  4023. if(product_id.length>0)
  4024. [arr addObject:noteRowAction];
  4025. [arr addObject:deleteRowAction];
  4026. #ifndef SCANNER_ORDER
  4027. if(product_id.length>0&& is_rate==0)
  4028. [arr addObject:addWatchAction];
  4029. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0)
  4030. {
  4031. [arr addObject:editRowAction];
  4032. // [arr addObject:freeRowAction];
  4033. }
  4034. #endif
  4035. return arr;
  4036. // return @[deleteRowAction,addWatchAction, editRowAction,freeRowAction];
  4037. } else if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  4038. if (appDelegate.customer_type == CustomerTypeStore) {
  4039. #ifndef SCANNER_ORDER
  4040. return @[notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  4041. #else
  4042. return @[deleteRowAction];
  4043. #endif
  4044. } else {
  4045. // normal
  4046. // NSArray *actionArray = @[notifyMeAction,deleteRowAction,addWatchAction];
  4047. NSMutableArray *actionArray = [NSMutableArray array];
  4048. // move to backorder
  4049. NSDictionary *section_json = [self jsonAtSection:indexPath.section];
  4050. BOOL available = [[section_json objectForKey:@"available"] boolValue]; // available list
  4051. if (self.back_order_flag && available) {
  4052. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction];
  4053. [actionArray addObject:move2BackAction];
  4054. }
  4055. [actionArray addObjectsFromArray:@[notifyMeAction,deleteRowAction,addWatchAction]];
  4056. // edit price
  4057. NSMutableDictionary * item_json = nil;
  4058. if (self.back_order_flag) {
  4059. item_json = [[self itemJsonAtIndexPath:indexPath] mutableCopy];
  4060. } else {
  4061. item_json = [self.content_arr[indexPath.row] mutableCopy];
  4062. }
  4063. NSString* product_id = [item_json valueForKey:@"product_id"];
  4064. int is_rate = [item_json[@"is_rate"] intValue];
  4065. if(appDelegate.can_set_cart_price && product_id.length>0&& is_rate==0) {
  4066. // actionArray = @[move2BackAction,notifyMeAction,deleteRowAction,addWatchAction,editRowAction];
  4067. [actionArray addObject:editRowAction];
  4068. }
  4069. return actionArray;
  4070. }
  4071. }
  4072. else
  4073. #ifndef SCANNER_ORDER
  4074. return @[deleteRowAction,addWatchAction];
  4075. #else
  4076. return @[deleteRowAction];
  4077. #endif
  4078. }
  4079. - (void)tableView:(UITableView *)tableView
  4080. commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  4081. // NSMutableDictionary * item_json = [[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  4082. //
  4083. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  4084. //
  4085. //
  4086. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4087. //
  4088. // NSDictionary* cart_json = [iSalesNetwork cart_remove:ids];
  4089. //
  4090. // dispatch_async(dispatch_get_main_queue(), ^{
  4091. //
  4092. //
  4093. //
  4094. // if(cart_json!=nil)
  4095. // {
  4096. //
  4097. // [self reload_data];
  4098. // }
  4099. //
  4100. // });
  4101. // });
  4102. // sqlite3* db = [ApexMobileDB get_db];
  4103. // NSString* sql = [NSString stringWithFormat:@"delete from history where _id=%@",[self.data.pagedata[indexPath.row] valueForKey:@"_id"]];
  4104. // [ApexMobileDB execSql:sql db:db];
  4105. // [iSalesDB close_db:db];
  4106. //
  4107. // [self.data.pagedata removeObjectAtIndex:indexPath.row];
  4108. //
  4109. // [tableView reloadData];
  4110. }
  4111. //#pragma mark - UIAlertViewDelegate
  4112. //// Called when a button is clicked. The view will be automatically dismissed after this call returns
  4113. //- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  4114. //{
  4115. //
  4116. // if(alertView.tag==ALERT_DEL)
  4117. // {
  4118. // if(buttonIndex!=alertView.cancelButtonIndex)
  4119. // {
  4120. // // [self.itemListTable reloadRowsAtIndexPaths:@[self.indexPath]withRowAnimation:UITableViewRowAnimationMiddle];
  4121. // NSMutableDictionary * item_json = nil;
  4122. // if (self.back_order_flag) {
  4123. // item_json = [[self itemJsonAtIndexPath:self.indexPath] mutableCopy];
  4124. // } else {
  4125. // item_json = [self.content_arr[self.indexPath.row] mutableCopy];//[[self.content_data objectForKey:[NSString stringWithFormat:@"item_%ld",(long)indexPath.row]] mutableCopy];
  4126. //
  4127. // }
  4128. //
  4129. // NSString *ids=[NSString stringWithFormat:@"%d",[[item_json valueForKey:@"cart_item_id"] intValue]];
  4130. // [RANetwork request_remove_cart:ids completionHandler:^(NSMutableDictionary *result) {
  4131. // NSMutableDictionary* cart_json = result;
  4132. //
  4133. //
  4134. //
  4135. //
  4136. // if([[cart_json valueForKey:@"result"] intValue]==2)
  4137. // {
  4138. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4139. // if (self.back_order_flag) {
  4140. //
  4141. // NSInteger section_count = [self sectionCount];
  4142. // for (int i = 0; i < section_count; i++) {
  4143. // NSInteger item_count = [self itemCountInSection:i];
  4144. // BOOL ready_break = NO;
  4145. //
  4146. // for (int j = 0; j < item_count; j++) {
  4147. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4148. // NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4149. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4150. // if([_id isEqualToString:ids])
  4151. // {
  4152. // [self updateItemJson:nil atIndexPath:indexPath];
  4153. // ready_break = YES;
  4154. // break;
  4155. // }
  4156. // }
  4157. //
  4158. // if (ready_break) {
  4159. // break;
  4160. // }
  4161. // }
  4162. //
  4163. // } else {
  4164. // for(int i=0;i<self.content_arr.count;i++)
  4165. // {
  4166. // NSDictionary* obj_json = self.content_arr[i];
  4167. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4168. // if([_id isEqualToString:ids])
  4169. // {
  4170. // [self.content_arr removeObjectAtIndex:i];
  4171. // // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4172. // break;
  4173. // // appDelegate.cart_count--;
  4174. // // [appDelegate update_count_mark];
  4175. // }
  4176. //
  4177. // }
  4178. // }
  4179. // [self.itemListTable reloadData];
  4180. // [self refresh_total];
  4181. //#ifdef RA_NOTIFICATION
  4182. // [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4183. //#else
  4184. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4185. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4186. //#endif
  4187. // // [self reload_data];
  4188. // }
  4189. // else
  4190. // {
  4191. // [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  4192. // }
  4193. //
  4194. //
  4195. // }];
  4196. //
  4197. //// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4198. ////
  4199. //// NSDictionary* cart_json = [RANetwork cart_remove:ids];
  4200. ////
  4201. //// dispatch_async(dispatch_get_main_queue(), ^{
  4202. ////
  4203. ////
  4204. ////
  4205. //// if([[cart_json valueForKey:@"result"] intValue]==2)
  4206. //// {
  4207. //// // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4208. //// if (self.back_order_flag) {
  4209. ////
  4210. //// NSInteger section_count = [self sectionCount];
  4211. //// for (int i = 0; i < section_count; i++) {
  4212. //// NSInteger item_count = [self itemCountInSection:i];
  4213. //// BOOL ready_break = NO;
  4214. ////
  4215. //// for (int j = 0; j < item_count; j++) {
  4216. //// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4217. //// NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4218. //// NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4219. //// if([_id isEqualToString:ids])
  4220. //// {
  4221. //// [self updateItemJson:nil atIndexPath:indexPath];
  4222. //// ready_break = YES;
  4223. //// break;
  4224. //// }
  4225. //// }
  4226. ////
  4227. //// if (ready_break) {
  4228. //// break;
  4229. //// }
  4230. //// }
  4231. ////
  4232. //// } else {
  4233. //// for(int i=0;i<self.content_arr.count;i++)
  4234. //// {
  4235. //// NSDictionary* obj_json = self.content_arr[i];
  4236. //// NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4237. //// if([_id isEqualToString:ids])
  4238. //// {
  4239. //// [self.content_arr removeObjectAtIndex:i];
  4240. //// // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4241. //// break;
  4242. //// // appDelegate.cart_count--;
  4243. //// // [appDelegate update_count_mark];
  4244. //// }
  4245. ////
  4246. //// }
  4247. //// }
  4248. //// [self.itemListTable reloadData];
  4249. //// [self refresh_total];
  4250. ////#ifdef RA_NOTIFICATION
  4251. //// [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4252. ////#else
  4253. //// AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4254. //// [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4255. ////#endif
  4256. //// // [self reload_data];
  4257. //// }
  4258. //// else
  4259. //// {
  4260. //// [RAUtils message_alert:[cart_json valueForKey:@"err_msg"] title:@"Delete Model" controller:self] ;
  4261. //// }
  4262. ////
  4263. //// });
  4264. //// });
  4265. //
  4266. // }
  4267. // }
  4268. //
  4269. //}
  4270. #pragma mark - Support scanner
  4271. -(void) onDecodedData:(NSString*) value
  4272. {
  4273. int cqty=0;
  4274. if (self.back_order_flag) {
  4275. NSInteger section_count = [self sectionCount];
  4276. for (int i = 0; i < section_count; i++) {
  4277. NSInteger item_count = [self itemCountInSection:i];
  4278. for (int j = 0; j < item_count; j++) {
  4279. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4280. NSDictionary* item = [self itemJsonAtIndexPath:indexPath];
  4281. if([item[@"model"] isEqualToString:value]) {
  4282. cqty=[item[@"count"] intValue];
  4283. }
  4284. }
  4285. }
  4286. } else {
  4287. for(int i=0;i<self.content_arr.count;i++)
  4288. {
  4289. NSDictionary* item= self.content_arr[i];
  4290. if([item[@"model"] isEqualToString:value])
  4291. cqty=[item[@"count"]intValue];
  4292. }
  4293. }
  4294. if(cqty>0)
  4295. {
  4296. UIAlertController *alertControl = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"QTY: %d of this model already in cart. Continue ?",cqty] message:nil preferredStyle:UIAlertControllerStyleAlert];
  4297. //block代码块取代了delegate
  4298. UIAlertAction *actionOne = [UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  4299. [self addtocart:value];
  4300. }];
  4301. UIAlertAction *alertthree = [UIAlertAction actionWithTitle:@"No" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  4302. DebugLog(@"No");
  4303. }];
  4304. [alertControl addAction:actionOne];
  4305. [alertControl addAction:alertthree];
  4306. //UIAlertControllerStyle类型为UIAlertControllerStyleAlert可以添加addTextFieldWithConfigurationHandler:^(UITextField *textField)
  4307. [self presentViewController:alertControl animated:YES completion:nil];
  4308. }
  4309. else
  4310. [self addtocart:value];
  4311. }
  4312. -(void) addtocart:(NSString*) modelname
  4313. {
  4314. [RANetwork request_addto_cart_byname:modelname withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  4315. NSDictionary* return_json =result;
  4316. if([[return_json valueForKey:@"result"] intValue]==2)
  4317. {
  4318. NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  4319. NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  4320. // bool isnew=false;
  4321. //
  4322. // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  4323. if (self.back_order_flag) {
  4324. NSInteger section_count = [self sectionCount];
  4325. for (int i = 0; i < section_count; i++) {
  4326. NSInteger item_count = [self itemCountInSection:i];
  4327. BOOL ready_break = NO;
  4328. for (int j = 0; j < item_count; j++) {
  4329. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4330. NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4331. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4332. if([_id isEqualToString:item_id])
  4333. {
  4334. [self updateItemJson:nil atIndexPath:indexPath];
  4335. ready_break = YES;
  4336. break;
  4337. }
  4338. }
  4339. if (ready_break) {
  4340. break;
  4341. }
  4342. }
  4343. } else {
  4344. for(int i=0;i<self.content_arr.count;i++)
  4345. {
  4346. NSDictionary* obj_json = self.content_arr[i];
  4347. NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4348. if([_id isEqualToString:item_id])
  4349. {
  4350. // self.content_arr[i] = newitem;
  4351. [self.content_arr removeObjectAtIndex:i];
  4352. break;
  4353. // [self.content_arr removeObjectAtIndex:i];
  4354. // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4355. // appDelegate.cart_count--;
  4356. // [appDelegate update_count_mark];
  4357. }
  4358. }
  4359. }
  4360. AppDelegate *appDelegate =nil;
  4361. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4362. #ifdef OFFLINE_MODE
  4363. if(appDelegate.offline_mode)
  4364. {
  4365. [self ReloadData];
  4366. }
  4367. else
  4368. #endif
  4369. {
  4370. if (self.back_order_flag) {
  4371. [self ReloadData];
  4372. } else {
  4373. [self.content_arr insertObject:newitem atIndex:0];
  4374. [self.itemListTable reloadData];
  4375. [self refresh_total];
  4376. }
  4377. }
  4378. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4379. #ifdef RA_NOTIFICATION
  4380. [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4381. #else
  4382. [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  4383. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4384. #endif
  4385. }
  4386. else
  4387. {
  4388. [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  4389. }
  4390. }];
  4391. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4392. //
  4393. // NSDictionary* return_json = [RANetwork add_toCart_byName: modelname withScreen:ScreenCodeCart];
  4394. //
  4395. // dispatch_async(dispatch_get_main_queue(), ^{
  4396. //
  4397. //
  4398. //
  4399. // if([[return_json valueForKey:@"result"] intValue]==2)
  4400. // {
  4401. // NSDictionary* newitem = [return_json objectForKey:@"item_0"];
  4402. // NSString* item_id = [newitem valueForKey:@"cart_item_id"];
  4403. // // bool isnew=false;
  4404. ////
  4405. // // [((MainViewController*)appDelegate.main_vc) reloadWish:true immediately:false];
  4406. //
  4407. // if (self.back_order_flag) {
  4408. //
  4409. // NSInteger section_count = [self sectionCount];
  4410. // for (int i = 0; i < section_count; i++) {
  4411. // NSInteger item_count = [self itemCountInSection:i];
  4412. // BOOL ready_break = NO;
  4413. // for (int j = 0; j < item_count; j++) {
  4414. // NSIndexPath *indexPath = [NSIndexPath indexPathForRow:j inSection:i];
  4415. // NSDictionary* obj_json = [self itemJsonAtIndexPath:indexPath];
  4416. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4417. // if([_id isEqualToString:item_id])
  4418. // {
  4419. // [self updateItemJson:nil atIndexPath:indexPath];
  4420. // ready_break = YES;
  4421. // break;
  4422. // }
  4423. // }
  4424. // if (ready_break) {
  4425. // break;
  4426. // }
  4427. //
  4428. //
  4429. // }
  4430. //
  4431. // } else {
  4432. //
  4433. // for(int i=0;i<self.content_arr.count;i++)
  4434. // {
  4435. // NSDictionary* obj_json = self.content_arr[i];
  4436. // NSString* _id =[obj_json valueForKey:@"cart_item_id"];
  4437. // if([_id isEqualToString:item_id])
  4438. // {
  4439. // // self.content_arr[i] = newitem;
  4440. //
  4441. //
  4442. // [self.content_arr removeObjectAtIndex:i];
  4443. //
  4444. // break;
  4445. // // [self.content_arr removeObjectAtIndex:i];
  4446. // // [self.itemListTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
  4447. // // appDelegate.cart_count--;
  4448. // // [appDelegate update_count_mark];
  4449. // }
  4450. //
  4451. //
  4452. // }
  4453. // }
  4454. //
  4455. // AppDelegate *appDelegate =nil;
  4456. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4457. //#ifdef OFFLINE_MODE
  4458. //
  4459. // if(appDelegate.offline_mode)
  4460. // {
  4461. //
  4462. // [self ReloadData];
  4463. //
  4464. // }
  4465. // else
  4466. //#endif
  4467. // {
  4468. //
  4469. // if (self.back_order_flag) {
  4470. // [self ReloadData];
  4471. // } else {
  4472. // [self.content_arr insertObject:newitem atIndex:0];
  4473. //
  4474. // [self.itemListTable reloadData];
  4475. // [self refresh_total];
  4476. // }
  4477. //
  4478. // }
  4479. //
  4480. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4481. //
  4482. //
  4483. //
  4484. //
  4485. //#ifdef RA_NOTIFICATION
  4486. // [ActiveViewController Notify:@"CartViewController,OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4487. //#else
  4488. // [((MainViewController*)appDelegate.main_vc) reloadCart:true immediately:false];
  4489. // [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4490. //#endif
  4491. //
  4492. //
  4493. // }
  4494. // else
  4495. // {
  4496. //
  4497. // [RAUtils message_alert:[return_json valueForKey:@"err_msg"] title:@"Add To Cart" controller:self] ;
  4498. // }
  4499. //
  4500. //
  4501. //
  4502. //
  4503. // });
  4504. // });
  4505. }
  4506. #pragma mark - sort button
  4507. - (void)cartSortButtonClicked:(UIButton *)sender {
  4508. DebugLog(@"cart sort button clicked");
  4509. [self.view addSubview:self.sortItemController.view];
  4510. }
  4511. - (SortItemViewController *)sortItemController {
  4512. if (!_sortItemController) {
  4513. _sortItemController = [[SortItemViewController alloc] initWithTableOrigin:CGPointMake(20, 50)];
  4514. _sortItemController.sortIndex = self.sortIndex;
  4515. _sortItemController.sortData = @[
  4516. @{@"title":@"Last",@"icon":@"TX_18"},
  4517. @{@"title":@"First",@"icon":@"TS_18"},
  4518. @{@"title":@"Item number a-z",@"icon":@"IX_18"},
  4519. @{@"title":@"Item number z-a",@"icon":@"IS_18"},
  4520. @{@"title":@"Description",@"icon":@"DX_18"},
  4521. ];
  4522. __weak typeof(self) weakSelf = self;
  4523. _sortItemController.sortBlock = ^(int sort){
  4524. weakSelf.sortIndex = sort;
  4525. [weakSelf reload_data];
  4526. };
  4527. }
  4528. // _sortItemController.sortIndex = self.sortIndex;
  4529. return _sortItemController;
  4530. }
  4531. - (SortButton *)sortButton {
  4532. if (!_sortButton) {
  4533. _sortButton = [SortButton sortButtonWithHeight:40];
  4534. _sortButton.autoresizingMask=UIViewAutoresizingFlexibleRightMargin;
  4535. [_sortButton addTarget:self action:@selector(cartSortButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  4536. }
  4537. return _sortButton;
  4538. }
  4539. - (void)setSortIndex:(int)sortIndex {
  4540. _sortIndex = sortIndex;
  4541. NSString *selectedImageName = @"";
  4542. switch (sortIndex) {
  4543. case 0:{
  4544. selectedImageName = @"TX_22";
  4545. }
  4546. break;
  4547. case 1:{
  4548. selectedImageName = @"TS_22";
  4549. }
  4550. break;
  4551. case 2:{
  4552. selectedImageName = @"IX_22";
  4553. }
  4554. break;
  4555. case 3:{
  4556. selectedImageName = @"IS_22";
  4557. }
  4558. break;
  4559. case 4:{
  4560. selectedImageName = @"DX_22";
  4561. }
  4562. break;
  4563. default:
  4564. break;
  4565. }
  4566. self.sortButton.imageView.image = [UIImage imageNamed:selectedImageName];
  4567. }
  4568. #pragma mark - rotation
  4569. //- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  4570. //
  4571. // self.sortItemController.view.frame = self.view.bounds;
  4572. //}
  4573. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  4574. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  4575. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  4576. // what ever you want to prepare
  4577. } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  4578. // self.sortItemController.view.frame = self.view.bounds;
  4579. self.sortItemController.view.frame = self.view.bounds;
  4580. self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  4581. // [self.itemListTable reloadData];
  4582. self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  4583. [self layoutCartIndicatorBar];
  4584. }];
  4585. }
  4586. -(BOOL) shouldAutorotate
  4587. {
  4588. return YES;
  4589. }
  4590. //- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  4591. // return YES;
  4592. //}
  4593. //- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  4594. // self.sortItemController.view.frame = self.view.bounds;
  4595. // self.toolpanel.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.toolpanel.bounds].CGPath;
  4596. //
  4597. //// [self.itemListTable reloadData];
  4598. //
  4599. // self.cartIndicatorBar.layer.shadowPath =[UIBezierPath bezierPathWithRect:self.cartIndicatorBar.bounds].CGPath;
  4600. // [self layoutCartIndicatorBar];
  4601. //}
  4602. #pragma mark - notification action
  4603. - (void)priceTypeChanged:(id)notification {
  4604. [self reload_data];
  4605. #ifdef RA_NOTIFICATION
  4606. [ActiveViewController Notify:@"OrderListViewController" Message:RA_NOTIFICATION_RELOAD_DATA];
  4607. #else
  4608. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4609. [((MainViewController*)appDelegate.main_vc) reloadOrder:true immediately:false];
  4610. #endif
  4611. }
  4612. #pragma mark - button action
  4613. - (IBAction)emailButtonClick:(UIButton *)sender {
  4614. if (![self isOrderAvailable]) {
  4615. return;
  4616. }
  4617. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4618. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"Please enter email address"];
  4619. emailAddrVC.textFiled.secureTextEntry = NO;
  4620. emailAddrVC.yesButtonTitle = @"send";
  4621. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  4622. __weak typeof(self) weakself = self;
  4623. emailAddrVC.textHandler = ^(NSString *text){
  4624. // 验证邮箱格式是否正确
  4625. // NSString *match = EMAIL_MATCHES;
  4626. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  4627. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  4628. BOOL isEmailAddr = YES;
  4629. if (isEmailAddr) {
  4630. // 验证是邮件地址,发送邮件
  4631. [weakVC dismissViewControllerAnimated:YES completion:^{
  4632. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  4633. [RANetwork request_qouteorder:appDelegate.order_code emailAddr:text completionHandler:^(NSMutableDictionary *result) {
  4634. DebugLog(@"email cart result: %@",result);
  4635. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  4636. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  4637. if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  4638. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  4639. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4640. }];
  4641. [errorAlertVC addAction:action];
  4642. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4643. }else {
  4644. [RAUtils message_alert:@"Send Email Success" title:@"Message" controller:weakself];
  4645. }
  4646. }];
  4647. }];
  4648. }];
  4649. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  4650. //
  4651. // NSDictionary *result = [RANetwork quoteOrder:appDelegate.order_code emailAddr:text];
  4652. // DebugLog(@"email cart result: %@",result);
  4653. // dispatch_async(dispatch_get_main_queue(), ^{
  4654. //
  4655. // [waitting_alert dismissWithClickedButtonIndex:0 animated:YES];
  4656. //
  4657. // if ([[result objectForKey:@"result"] integerValue] != RESULT_TRUE) {
  4658. //
  4659. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"The email send to %@ failed",text] preferredStyle:UIAlertControllerStyleAlert];
  4660. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4661. //
  4662. // }];
  4663. //
  4664. // [errorAlertVC addAction:action];
  4665. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4666. //
  4667. // }else {
  4668. //
  4669. // [RAUtils message_alert:@"Send Email Success" title:@"Message" controller:weakself];
  4670. //
  4671. // }
  4672. //
  4673. // });
  4674. //
  4675. // });
  4676. }];
  4677. } else {
  4678. // 非邮件地址,警告
  4679. [weakVC warning:@"Please enter right email address"];
  4680. }
  4681. };
  4682. [self presentViewController:emailAddrVC animated:YES completion:nil];
  4683. }
  4684. - (IBAction)printCartButtonClick:(UIButton *)sender {
  4685. if (![self isOrderAvailable]) {
  4686. return;
  4687. }
  4688. RAPDFViewController *ViewController = [[UIStoryboard storyboardWithName:@"wkweb" bundle:nil] instantiateViewControllerWithIdentifier:@"RAPDFViewController"];
  4689. ViewController.url = self.print_url;
  4690. ViewController.canSave = false;
  4691. ViewController.isLocalfile=NO;
  4692. NSString* subject;
  4693. subject =@"Cart Print";
  4694. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4695. NSString* customer_email= [appDelegate.customerInfo valueForKey:@"customer_email"];
  4696. NSMutableArray* send_to = [[NSMutableArray alloc]init];
  4697. if(customer_email.length>0)
  4698. {
  4699. send_to=[[customer_email componentsSeparatedByString:NSLocalizedString(@";", nil)] mutableCopy];
  4700. }
  4701. ViewController.mail_to = send_to;
  4702. ViewController.filename = [NSString stringWithFormat:@"%@_Product_List.pdf",COMPANY_SHORT_NAME];
  4703. ViewController.mail_subject = subject;
  4704. ViewController.hidenavi = false;
  4705. [self.navigationController pushViewController:ViewController animated:YES];
  4706. }
  4707. - (void)showAddressBoxToEmailProduct:(NSString *)productID {
  4708. // AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  4709. JKMessageBoxController *emailAddrVC = [JKMessageBoxController messageBoxControllerWithTip:@"E-mail not setup, please enter your default e-mail address" ContentSize:CGSizeMake(400, 150)];
  4710. emailAddrVC.textFiled.secureTextEntry = NO;
  4711. emailAddrVC.yesButtonTitle = @"send";
  4712. __weak typeof(emailAddrVC) weakVC = emailAddrVC;
  4713. __weak typeof(self) weakself = self;
  4714. emailAddrVC.textHandler = ^(NSString *text){
  4715. // 验证邮箱格式是否正确
  4716. // NSString *match = EMAIL_MATCHES;
  4717. // NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];
  4718. // BOOL isEmailAddr = [predicate evaluateWithObject:text];
  4719. BOOL isEmailAddr = YES;
  4720. if (isEmailAddr) {
  4721. // 验证是邮件地址,发送邮件
  4722. [weakVC dismissViewControllerAnimated:YES completion:^{
  4723. __block UIAlertController *waitting_alert = [RAUtils waiting_alert:self title:@"Sending Email" completion:^{
  4724. [RANetwork request_notifymodel:productID emailAddr:text withScreen:ScreenCodeCart completionHandler:^(NSMutableDictionary *result) {
  4725. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  4726. [waitting_alert dismissViewControllerAnimated:YES completion:^{
  4727. int resultStatus = [[result objectForKey:@"result"] intValue];
  4728. if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  4729. NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  4730. if ([result valueForKey:@"err_msg"]) {
  4731. msg = [result valueForKey:@"err_msg"];
  4732. }
  4733. UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  4734. UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4735. }];
  4736. [errorAlertVC addAction:action];
  4737. [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4738. }else if(resultStatus == RESULT_TRUE){
  4739. [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  4740. } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  4741. [weakself showAddressBoxToEmailProduct:productID];
  4742. }
  4743. }];
  4744. }];
  4745. }];
  4746. // dispatch_async(dispatch_get_global_queue(0, 0), ^{
  4747. //
  4748. // NSDictionary *result = [RANetwork notifyModel:productID emailAddr:text withScreen:ScreenCodeCart];
  4749. //
  4750. // dispatch_async(dispatch_get_main_queue(), ^{
  4751. //
  4752. // [waitting_alert dismissWithClickedButtonIndex:0 animated:NO];
  4753. //
  4754. // int resultStatus = [[result objectForKey:@"result"] intValue];
  4755. // if (resultStatus != RESULT_TRUE && resultStatus != RESULT_NO_EMAIL_ADDRESS) {
  4756. //
  4757. // NSString *msg = [NSString stringWithFormat:@"The email send failed"];
  4758. // if ([result valueForKey:@"err_msg"]) {
  4759. // msg = [result valueForKey:@"err_msg"];
  4760. // }
  4761. //
  4762. //
  4763. // UIAlertController *errorAlertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
  4764. // UIAlertAction *action = [UIAlertAction actionWithTitle:@"ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  4765. //
  4766. // }];
  4767. //
  4768. // [errorAlertVC addAction:action];
  4769. // [weakself presentViewController:errorAlertVC animated:YES completion:nil];
  4770. //
  4771. // }else if(resultStatus == RESULT_TRUE){
  4772. //
  4773. // [RAUtils message_alert:@"Notification is sent to default email address." title:@"Message" controller:weakself];
  4774. //
  4775. // } else if (resultStatus == RESULT_NO_EMAIL_ADDRESS) {
  4776. //
  4777. // [weakself showAddressBoxToEmailProduct:productID];
  4778. //
  4779. // }
  4780. //
  4781. // });
  4782. //
  4783. // });
  4784. }];
  4785. } else {
  4786. // 非邮件地址,警告
  4787. [weakVC warning:@"Please enter right email address"];
  4788. }
  4789. };
  4790. [self presentViewController:emailAddrVC animated:YES completion:nil];
  4791. }
  4792. #pragma mark - Back Order
  4793. - (void) setCart_json:(NSDictionary *)cart_json {
  4794. _cart_json = cart_json;
  4795. [self fillContentArray];
  4796. }
  4797. - (void)fillContentArray {
  4798. NSMutableArray *arr = [NSMutableArray array];
  4799. for (int i = 0; i < [self sectionCount]; i++) {
  4800. NSInteger item_count = [self itemCountInSection:i];
  4801. for (int j = 0; j < item_count; j++) {
  4802. NSDictionary *item = [self itemJsonAtIndexPath:[NSIndexPath indexPathForRow:j inSection:i]];
  4803. [arr addObject:item];
  4804. }
  4805. }
  4806. self.content_arr = arr;
  4807. [self refresh_total];
  4808. }
  4809. - (NSInteger)sectionCount {
  4810. return [[self.cart_json objectForKey:@"section_count"] integerValue];
  4811. }
  4812. - (NSDictionary *)jsonAtSection:(NSInteger)section {
  4813. return [self.cart_json objectForKey:[NSString stringWithFormat:@"section_%ld",section]];
  4814. }
  4815. - (NSInteger)itemCountInSection:(NSInteger)section {
  4816. NSDictionary *section_json = [self jsonAtSection:section];
  4817. return [[section_json objectForKey:@"count"] integerValue];
  4818. }
  4819. - (NSString *)titleForSection:(NSInteger)section {
  4820. NSDictionary *section_json = [self jsonAtSection:section];
  4821. return [section_json objectForKey:@"title"];
  4822. }
  4823. - (NSDictionary *)itemJsonAtIndexPath:(NSIndexPath *)indexPath {
  4824. NSDictionary *section = [self jsonAtSection:indexPath.section];
  4825. return [section objectForKey:[NSString stringWithFormat:@"item_%ld",indexPath.row]];
  4826. }
  4827. - (void)updateItemJson:(NSDictionary *)new_item_json atIndexPath:(NSIndexPath *)indexPath {
  4828. NSMutableDictionary *new_cart_json = [self.cart_json mutableCopy];
  4829. NSMutableDictionary *new_section_json = [[self jsonAtSection:indexPath.section] mutableCopy];
  4830. NSString *section_key = [NSString stringWithFormat:@"section_%ld",indexPath.section];
  4831. NSString *item_key = [NSString stringWithFormat:@"item_%ld",indexPath.row];
  4832. if (new_item_json) {
  4833. // 更新Item
  4834. [new_section_json setObject:new_item_json forKey:item_key];
  4835. } else {
  4836. // 删除Item
  4837. NSInteger item_count = [self itemCountInSection:indexPath.section];
  4838. for (NSInteger i = 0; i < item_count; i++) {
  4839. if (i >= indexPath.row) {
  4840. if (i < item_count - 1) {
  4841. item_key = [NSString stringWithFormat:@"item_%ld",i + 1];
  4842. NSDictionary *followed_item_json = [new_section_json objectForKey:item_key];
  4843. item_key = [NSString stringWithFormat:@"item_%ld",i];
  4844. [new_section_json setObject:followed_item_json forKey:item_key];
  4845. } else {
  4846. item_key = [NSString stringWithFormat:@"item_%ld",i];
  4847. [new_section_json removeObjectForKey:item_key];
  4848. }
  4849. }
  4850. }
  4851. [new_section_json setObject:@(item_count - 1) forKey:@"count"];
  4852. }
  4853. [new_cart_json setObject:new_section_json forKey:section_key];
  4854. self.cart_json = [new_cart_json copy];
  4855. }
  4856. - (void)reRefreshView {
  4857. [self.itemListTable reloadData];
  4858. }
  4859. #pragma mark - RA_NOTIFICAITON
  4860. -(void) refresh_ui
  4861. {
  4862. [self.itemListTable reloadData];
  4863. [self refresh_total];
  4864. }
  4865. -(void) refresh_price
  4866. {
  4867. [self refresh_ui];
  4868. }
  4869. - (void) reload_data {
  4870. __weak typeof(self) weakself = self;
  4871. self.currentOrderIsMerged = NO;
  4872. NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
  4873. if (weakself) {
  4874. __strong typeof(weakself) strongself = weakself;
  4875. [strongself operation_reload_data];
  4876. }
  4877. }];
  4878. [self.dataOperationQueue addOperation:operation];
  4879. }
  4880. @end