CartViewController.m 255 KB

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