CartViewController.m 223 KB

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