Source of file api.warehouse.php
Size: 226,925 Bytes - Last Modified: 2024-04-27T15:26:05+03:00
/tmp/current_snapshot/api/libs/api.warehouse.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300 | <?php /** * Basic warehouse accounting implementation */ class Warehouse { /** * Contains all available employee as employeeid=>name * * @var array */ protected $allEmployee = array(); /** * Contains all active employee as employeeid=>name * * @var array */ protected $activeEmployee = array(); /** * Contains available employee telegram chatid data as id=>chatid * * @var array */ protected $allEmployeeTelegram = array(); /** * Contains all available employee realnames as login=>name * * @var array */ protected $allEmployeeLogins = array(); /** * System alter.ini config stored as array key=>value * * @var array */ protected $altCfg = array(); /** * List of all available items categories as id=>category name * * @var array */ protected $allCategories = array(); /** * List of all available item types as id=>data * * @var array */ protected $allItemTypes = array(); /** * Contains all item type names as id=>name * * @var array */ protected $allItemTypeNames = array(); /** * All of available warehouse storages as id=>name * * @var array */ protected $allStorages = array(); /** * All of available warehouse contractors as id=>name * * @var array */ protected $allContractors = array(); /** * All available incoming operations * * @var array */ protected $allIncoming = array(); /** * All available outcoming operations as id=>outcomeData * * @var array */ protected $allOutcoming = array(); /** * Preloaded reserve entries as id=>reserve data * * @var array */ protected $allReserve = array(); /** * Contains previous reservation history * * @var array */ protected $allReserveHistory = array(); /** * Contains reserve creation dates as reserveId=>date string array * * @var array */ protected $allReserveCreationDates = array(); /** * Available unit types as unittype=>localized name * * @var array */ protected $unitTypes = array(); /** * Available outcoming destinations as destination=>localized name * * @var array */ protected $outDests = array(); /** * Contains previously detected tasks outcomings mappings * * @var array */ protected $taskOutsCache = array(); /** * System messages helper object placeholder * * @var object */ protected $messages = ''; /** * System telegram object placeholder * * @var object */ protected $telegram = ''; /** * Returns database abstraction layer placeholder * * @var object */ protected $returnsDb = ''; /** * Contains all returns operation as outcomeid=>returnData * * @var array */ protected $allReturns = array(); /** * Telegram force notification flag * * @var bool */ protected $telegramNotify = false; /** * System caching object placeholder * * @var object */ protected $cache = ''; /** * Default asterisk required fields notifier * * @var string */ protected $sup = ''; /** * Recommended price flag * * @var bool */ protected $recPriceFlag = false; /** * Default constants/routes/URLS etc.. */ const URL_ME = '?module=warehouse'; const URL_CATEGORIES = 'categories=true'; const URL_ITEMTYPES = 'itemtypes=true'; const URL_STORAGES = 'storages=true'; const URL_CONTRACTORS = 'contractors=true'; const URL_IN = 'in=true'; const URL_OUT = 'out=true'; const URL_OUTAJREMAINS = 'ajaxremains=true'; const URL_AJITSELECTOR = 'ajits='; const URL_AJODSELECTOR = 'ajods='; const URL_INAJLIST = 'ajaxinlist=true'; const URL_REAJTREM = 'ajaxtremains=true'; const URL_OUTAJLIST = 'ajaxoutlist=true'; const URL_VIEWERS = 'viewers=true'; const URL_REPORTS = 'reports=true'; const URL_RESERVE = 'reserve=true'; const ROUTE_DELOUT = 'outcomedelete'; const ROUTE_DELIN = 'incomedelete'; const PROUTE_MASSRESERVEOUT = 'massoutreserves'; const PROUTE_MASSAGREEOUT = 'massoutagreement'; const PROUTE_DOMASSRESOUT = 'runmassoutreserve'; const PROUTE_RETURNOUTID = 'newreturnoutcomeid'; const PROUTE_RETURNSTORAGE = 'newreturnstorageid'; const PROUTE_RETURNPRICE = 'newreturnprice'; const PROUTE_RETURNNOTE = 'newreturnnote'; const PROUTE_EMPREPLACE = 'massoutemployeereplace'; const PHOTOSTORAGE_SCOPE = 'WAREHOUSEITEMTYPE'; /** * Default debug log path */ const LOG_PATH = 'exports/whdebug.log'; /** * Some caching default timeout */ const CACHE_TIMEOUT = 2592000; /** * Creates new warehouse instance * * @param type $taskid * * @return void */ public function __construct($taskid = '') { $this->loadAltCfg(); $this->setOptions(); $this->loadOutOperations($taskid); $this->setUnitTypes(); $this->setOutDests(); $this->setSup(); $this->loadMessages(); $this->loadAllEmployeeData(); $this->loadCategories(); $this->loadItemTypes(); $this->loadStorages(); $this->loadContractors(); $this->initTelegram(); $this->initCache(); $this->loadTaskOutsCache(); $this->initReturns(); if (empty($taskid)) { $this->loadReserve(); $this->loadReserveHistory(); $this->loadInOperations(); } } /** * Loads system alter config * * @global object $ubillingConfig * * @return void */ protected function loadAltCfg() { global $ubillingConfig; $this->altCfg = $ubillingConfig->getAlter(); } /** * Sets some config based options * * @return void */ protected function setOptions() { if (isset($this->altCfg['WAREHOUSE_TELEGRAM']) and $this->altCfg['WAREHOUSE_TELEGRAM']) { $this->telegramNotify = true; } if (isset($this->altCfg['WAREHOUSE_RECPRICE']) and $this->altCfg['WAREHOUSE_RECPRICE']) { $this->recPriceFlag = true; } } /** * Creates system message helper object instance * * @return void */ protected function loadMessages() { $this->messages = new UbillingMessageHelper(); } /** * Inits telegram object as protected instance for further usage * * @return void */ protected function initTelegram() { if ($this->altCfg['SENDDOG_ENABLED']) { $this->telegram = new UbillingTelegram(); } } /** * Inits returns database abstraction layer * * @return void */ protected function initReturns() { if (@$this->altCfg['WAREHOUSE_RETURNS_ENABLED']) { $this->returnsDb = new NyanORM('wh_returns'); } } /** * Loads all existing return operations from database into protected prop * * @return void */ protected function loadReturns() { if (@$this->altCfg['WAREHOUSE_RETURNS_ENABLED']) { $this->allReturns = $this->returnsDb->getAll('outid'); } } /** * Inits system cache for further usage * * @return void */ protected function initCache() { $this->cache = new UbillingCache(); } /** * Loads tasks=>outcomings cache * * @return void */ protected function loadTaskOutsCache() { $this->taskOutsCache = $this->cache->get('TASKSOUTS', self::CACHE_TIMEOUT); if (empty($this->taskOutsCache)) { $this->taskOutsCache = array(); } } /** * Loads all existing employees from database * * @return void */ protected function loadAllEmployeeData() { $query = "SELECT * from `employee`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allEmployee[$each['id']] = $each['name']; if ($each['active']) { $this->activeEmployee[$each['id']] = $each['name']; } if (!empty($each['admlogin'])) { $this->allEmployeeLogins[$each['admlogin']] = $each['name']; } $this->allEmployeeTelegram[$each['id']] = $each['telegram']; } } } /** * Sets default unit types * * @return void */ protected function setUnitTypes() { $this->unitTypes['quantity'] = __('quantity'); $this->unitTypes['meter'] = __('meter'); $this->unitTypes['kilometer'] = __('kilometer'); $this->unitTypes['money'] = __('money'); $this->unitTypes['time'] = __('time'); $this->unitTypes['litre'] = __('litre'); $this->unitTypes['pieces'] = __('pieces'); $this->unitTypes['packing'] = __('packing'); } /** * Sets default unit types * * @return void */ protected function setOutDests() { $this->outDests['task'] = __('Task'); $this->outDests['contractor'] = __('Contractor'); $this->outDests['employee'] = __('Employee'); $this->outDests['storage'] = __('Warehouse storage'); $this->outDests['user'] = __('User'); $this->outDests['sale'] = __('Sale'); $this->outDests['cancellation'] = __('Cancellation'); $this->outDests['mistake'] = __('Mistake'); } /** * Sets default required fields notification * * @return void */ protected function setSup() { $this->sup = wf_tag('sup') . '*' . wf_tag('sup', true); } /** * Loads existing warehouse categories from DB * * @return void */ protected function loadCategories() { $query = "SELECT * from `wh_categories`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allCategories[$each['id']] = $each['name']; } } } /** * Loads all existing warehouse item types * * @return void */ protected function loadItemTypes() { $query = "SELECT* from `wh_itemtypes` ORDER BY `name` ASC"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allItemTypes[$each['id']] = $each; $this->allItemTypeNames[$each['id']] = $each['name']; } } } /** * Loads existing warehouse storages from DB * * @return void */ protected function loadStorages() { $query = "SELECT * from `wh_storages`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allStorages[$each['id']] = $each['name']; } } } /** * Loads existing warehouse contractors from DB * * @return void */ protected function loadContractors() { $query = "SELECT * from `wh_contractors`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allContractors[$each['id']] = $each['name']; } } } /** * Loads existing incoming operations from database * * @return void */ protected function loadInOperations() { $query = "SELECT * from `wh_in`"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allIncoming[$each['id']] = $each; } } } /** * Loads existing outcoming operations from database * * @param int $taskid existing taskId * * @return void */ protected function loadOutOperations($taskid = '') { $taskid = vf($taskid, 3); $where = (!empty($taskid)) ? "WHERE `desttype`='task' AND `destparam`='" . $taskid . "'" : ''; $query = "SELECT * from `wh_out` " . $where . ";"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allOutcoming[$each['id']] = $each; } } } /** * Loads available reserved items from database * * @return void */ protected function loadReserve() { $query = "SELECT * from `wh_reserve` ORDER BY `id` DESC"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allReserve[$each['id']] = $each; } } } /** * Loads reserve history logs from database * * @return void */ protected function loadReserveHistory() { $query = "SELECT * from `wh_reshist` ORDER BY `id` DESC"; $all = simple_queryall($query); if (!empty($all)) { foreach ($all as $io => $each) { $this->allReserveHistory[$each['id']] = $each; if (!empty($each['resid'])) { if ($each['type'] == 'create') { $this->allReserveCreationDates[$each['resid']] = $each['date']; } } } } } /** * Returns count of itemtypes reserved on storage if available * * @param int $storageId * @param int $itemtypeId * * @return float */ protected function reserveGet($storageId, $itemtypeId) { $result = 0; $storageId = vf($storageId, 3); $itemtypeId = vf($itemtypeId, 3); if (!empty($this->allReserve)) { foreach ($this->allReserve as $io => $each) { if (($each['storageid'] == $storageId) and ($each['itemtypeid'] == $itemtypeId)) { $result += $each['count']; } } } return ($result); } /** * Returns existing reserve data * * @param int $reserveId * * @return array */ protected function reserveGetData($reserveId) { $result = array(); if (isset($this->allReserve[$reserveId])) { $result = $this->allReserve[$reserveId]; } return ($result); } /** * Stores reservation history log record into database * * @param string $type - create/update/delete * @param int $storageId * @param int $itemtypeId * @param float $count * @param int $employeeId * @param int $reserveId */ protected function reservePushLog($type, $storageId = '', $itemtypeId = '', $count = '', $employeeId = '', $reserveId = '') { $curdate = curdatetime(); $type = vf($type); $adminLogin = mysql_real_escape_string(whoami()); $storageId = "'" . vf($storageId, 3) . "'"; $itemtypeId = "'" . vf($itemtypeId, 3) . "'"; $count = "'" . mysql_real_escape_string($count) . "'"; $employeeId = "'" . vf($employeeId, 3) . "'"; $reserveId = vf($reserveId, 3); $query = "INSERT INTO `wh_reshist` (`id`,`resid`,`date`,`type`,`storageid`,`itemtypeid`,`count`,`employeeid`,`admin`) VALUES "; $query .= "(NULL,'" . $reserveId . "','" . $curdate . "','" . $type . "'," . $storageId . "," . $itemtypeId . "," . $count . "," . $employeeId . ",'" . $adminLogin . "');"; nr_query($query); } /** * Stores Telegram message for some employee * * @param int $employeeid * @param string $message * * @return void */ protected function sendTelegram($employeeId, $message) { if ($this->altCfg['SENDDOG_ENABLED']) { $chatId = @$this->allEmployeeTelegram[$employeeId]; if (!empty($chatId)) { $this->telegram->sendMessage($chatId, $message, false, 'WAREHOUSE'); } } } /** * Sends some notificaton about reserve creation to employee * * @param int $storageId * @param int $itemtypeId * @param float $count * @param int $employeeId * @param int $reserveId * * @return void */ protected function reserveCreationNotify($storageId, $itemtypeId, $count, $employeeId, $reserveId = '') { if ($this->telegramNotify) { $message = ''; $adminLogin = whoami(); $adminName = (isset($this->allEmployeeLogins[$adminLogin])) ? $this->allEmployeeLogins[$adminLogin] : $adminLogin; $message .= __('From warehouse storage') . ' 📦 ' . $this->allStorages[$storageId] . '\r\n '; $message .= '👤 ' . $adminName . ' ' . __('reserved for you') . ' ' . '❤️️' . ' : '; $message .= $this->allItemTypeNames[$itemtypeId] . ' ' . $count . ' ' . $this->unitTypes[$this->allItemTypes[$itemtypeId]['unit']] . '\r\n '; $message .= __('Reserve') . '@' . $reserveId . ' 🔒'; $this->sendTelegram($employeeId, $message); } } /** * Sends reserve remains daily notifications to employees * * @return void */ public function telegramReserveDailyNotify() { if (!empty($this->allReserve)) { if ($this->altCfg['SENDDOG_ENABLED']) { $curdate = curdate(); $sendTmp = array(); //employeeid => text aggregated $reserveTmp = array(); //employeeid=>reserve data with aggr foreach ($this->allReserve as $io => $eachReserve) { $employeeId = $eachReserve['employeeid']; $chatId = @$this->allEmployeeTelegram[$employeeId]; $itemtypeId = $eachReserve['itemtypeid']; $itemCount = $eachReserve['count']; if (!empty($chatId)) { if (!isset($reserveTmp[$employeeId])) { $reserveTmp[$employeeId] = array(); } if (isset($reserveTmp[$employeeId][$itemtypeId])) { $reserveTmp[$employeeId][$itemtypeId] += $itemCount; } else { $reserveTmp[$employeeId][$itemtypeId] = $itemCount; } } } if (!empty($reserveTmp)) { foreach ($reserveTmp as $eachEmployee => $reservedItems) { $totalCostSumm = 0; $message = __('Is reserved for you') . '\r\n ';; foreach ($reservedItems as $eachItemId => $eachItemCount) { $message .= @$this->allItemTypeNames[$eachItemId] . ': ' . $eachItemCount . ' ' . @$this->unitTypes[$this->allItemTypes[$eachItemId]['unit']] . '\r\n '; $itemCost = $this->getIncomeMiddlePrice($eachItemId); $totalCostSumm += $itemCost * $eachItemCount; } $message .= '📦📦📦📦' . '\r\n '; // very vsrate emoji $message .= __('Total cost') . ': ' . $totalCostSumm . '\r\n '; //pugalo inside $message .= '💸💸💸💸' . '\r\n '; // dont ask me why $sendTmp[$eachEmployee] = $message; } } if (!empty($sendTmp)) { foreach ($sendTmp as $io => $eachMessage) { $this->sendTelegram($io, $eachMessage); } } } } } /** * Creates new reserve record in database * * @param int $storageId * @param int $itemtypeId * @param float $count * @param int $employeeId * * @return void/string if succefull or error message */ public function reserveCreate($storageId, $itemtypeId, $count, $employeeId) { $storageId = vf($storageId, 3); $itemtypeId = vf($itemtypeId, 3); $countF = mysql_real_escape_string($count); $countF = str_replace(',', '.', $countF); $employeeId = vf($employeeId, 3); $storageRemains = $this->remainsOnStorage($storageId); @$itemtypeRemains = $storageRemains[$itemtypeId]; if (empty($itemtypeRemains)) { $itemtypeRemains = 0; } $alreadyReserved = $this->reserveGet($storageId, $itemtypeId); $realRemains = $itemtypeRemains - $alreadyReserved; $result = ''; if (isset($this->allStorages[$storageId])) { if (isset($this->allItemTypes[$itemtypeId])) { if (isset($this->allEmployee[$employeeId])) { if ($realRemains >= $countF) { $query = "INSERT INTO `wh_reserve` (`id`,`storageid`,`itemtypeid`,`count`,`employeeid`) VALUES " . "(NULL,'" . $storageId . "','" . $itemtypeId . "','" . $countF . "','" . $employeeId . "')"; nr_query($query); $newId = simple_get_lastid('wh_reserve'); log_register('WAREHOUSE RESERVE CREATE [' . $newId . '] ITEM [' . $itemtypeId . '] COUNT `' . $count . '` EMPLOYEE [' . $employeeId . ']'); $this->reservePushLog('create', $storageId, $itemtypeId, $count, $employeeId, $newId); $this->reserveCreationNotify($storageId, $itemtypeId, $count, $employeeId, $newId); } else { $result = $this->messages->getStyledMessage($this->allItemTypeNames[$itemtypeId] . '. ' . __('The balance of goods and materials in stock is less than the amount') . ' (' . $countF . ' > ' . $itemtypeRemains . '-' . $alreadyReserved . ')', 'error'); } } else { $result = $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('No available workers for reserve creation'), 'error'); } } else { $result = $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('No existing warehouse item types'), 'error'); } } else { $result = $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('No existing warehouse storages'), 'error'); } return ($result); } /** * Creates mass reservation if required and returns its results as formatted notifications * * @return string */ public function reserveMassCreate() { $result = ''; $successCount = 0; if (wf_CheckPost(array('newmassemployeeid', 'newmassstorageid', 'newmasscreation'))) { $employeeId = vf($_POST['newmassemployeeid'], 3); $storageId = vf($_POST['newmassstorageid']); $postTmp = $_POST; foreach ($postTmp as $io => $each) { if (ispos($io, 'newmassitemtype_')) { $rawData = explode('_', $io); $itemtypeId = $rawData[1]; $itemCount = $each; if ($itemCount > 0) { $reserveResult = $this->reserveCreate($storageId, $itemtypeId, $itemCount, $employeeId); if (!empty($reserveResult)) { //some shit happened $result .= $reserveResult; } else { //success! $result .= $this->messages->getStyledMessage($this->allItemTypeNames[$itemtypeId] . '. ' . __('Reserved') . ' (' . $itemCount . ' ' . @$this->unitTypes[$this->allItemTypes[$itemtypeId]['unit']] . ')', 'success'); $successCount++; } } } } //live data update if ($successCount > 0) { $this->loadReserve(); } } return ($result); } /** * Renders current dayly items reserved for some employee * * @param int $employeeId * * @return string */ protected function reserveRenderTodayReserved($employeeId) { $employeeId = vf($employeeId, 3); $result = ''; if (!empty($this->allReserveHistory)) { $curDate = curdate(); foreach ($this->allReserveHistory as $io => $each) { if ($each['employeeid'] == $employeeId) { if ($each['type'] == 'create') { if (ispos($each['date'], $curDate)) { $itemtypeId = $each['itemtypeid']; $label = @$this->allItemTypeNames[$itemtypeId] . '. ' . __('Already reserved today') . ' (' . $each['count'] . ' ' . @$this->unitTypes[$this->allItemTypes[$itemtypeId]['unit']] . ')'; $result .= $this->messages->getStyledMessage($label, 'info'); } } } } } return ($result); } /** * Renders mass reservation form * * @return string */ public function reserveMassForm() { $result = ''; $emptyWarehouse = false; $realRemains = array(); $employeeTmp = array('' => '-'); $employeeTmp += $this->activeEmployee; $storageTmp = array('' => '-'); $storageTmp += $this->allStorages; if (!empty($this->allStorages)) { $inputs = wf_SelectorAC('newmassemployeeid', $employeeTmp, __('Employee'), @$_POST['newmassemployeeid'], true); if (wf_CheckPost(array('newmassemployeeid'))) { $inputs .= wf_SelectorAC('newmassstorageid', $storageTmp, __('Warehouse storage'), @$_POST['newmassstorageid'], true); if (wf_CheckPost(array('newmassstorageid'))) { $storageRemains = $this->remainsOnStorage($_POST['newmassstorageid']); if (!empty($storageRemains)) { foreach ($storageRemains as $io => $each) { $alreadyReserved = $this->reserveGet($_POST['newmassstorageid'], $io); $realCount = $each - $alreadyReserved; if ($realCount > 0) { $realRemains[$io] = $each - $alreadyReserved; } } if (empty($realRemains)) { $emptyWarehouse = true; } else { $cells = wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item types')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Reserve')); $rows = wf_TableRow($cells, 'row1'); foreach ($realRemains as $itemtypeId => $itemCount) { $itemTypeLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $itemtypeId, @$this->allItemTypeNames[$itemtypeId]); $cells = wf_TableCell(@$this->allCategories[$this->allItemTypes[$itemtypeId]['categoryid']]); $cells .= wf_TableCell($itemTypeLink); $cells .= wf_TableCell($itemCount . ' ' . @$this->unitTypes[$this->allItemTypes[$itemtypeId]['unit']]); $cells .= wf_TableCell(wf_TextInput('newmassitemtype_' . $itemtypeId, '', '0', false, 4)); $rows .= wf_TableRow($cells, 'row5'); } $inputs .= wf_TableBody($rows, '100%', 0, ''); $inputs .= wf_CheckInput('newmasscreation', __('I`m ready'), true, false); $inputs .= wf_tag('br'); $inputs .= wf_Submit(__('Reservation')); } } else { $emptyWarehouse = true; } } } $result .= wf_Form('', 'POST', $inputs, ''); if (wf_CheckPost(array('newmassemployeeid'))) { $result .= $this->reserveRenderTodayReserved(@$_POST['newmassemployeeid']); } if ($emptyWarehouse) { // ,_ /) (\ _, // >> <<,_,>> << // // _0.-.0_ \\ // \'._/ \_.'/ // '-.\.--.--./.-' // __/ : :Y: : \ _ //';, .-(_| : : | : : |_)-. ,:' // \\/.' |: : :|: : :| `.\// // (/ |: : :|: : :| \) // |: : :|: : :; // /\ : : | : : /\ // (_/'.: :.: :.'\_) // \\ `""`""` // // \\ // // ':. .:' $result .= $this->messages->getStyledMessage(__('Warehouse storage is empty'), 'warning'); } } return ($result); } /** * Returns itemtype reservation interface * * @param int $storageId * @param int $itemtypeId * * @return string */ public function reserveCreateForm($storageId, $itemtypeId) { $storageId = vf($storageId, 3); $itemtypeId = vf($itemtypeId, 3); $result = ''; if (isset($this->allStorages[$storageId])) { if (isset($this->allItemTypes[$itemtypeId])) { if (!empty($this->activeEmployee)) { $storageRemains = $this->remainsOnStorage($storageId); if (isset($storageRemains[$itemtypeId])) { $itemRemainsStorage = $storageRemains[$itemtypeId]; } else { $itemRemainsStorage = 0; } $alreadyReserved = $this->reserveGet($storageId, $itemtypeId); $itemtypeData = $this->allItemTypes[$itemtypeId]; $itemtypeName = $this->allItemTypeNames[$itemtypeId]; $itemtypeUnit = $this->unitTypes[$itemtypeData['unit']]; $inputs = wf_HiddenInput('newreserveitemtypeid', $itemtypeId); $inputs .= wf_HiddenInput('newreservestorageid', $storageId); $inputs .= wf_Selector('newreserveemployeeid', $this->activeEmployee, __('Worker'), '', true); $inputs .= wf_TextInput('newreservecount', $itemtypeUnit . ' (' . ($itemRemainsStorage - $alreadyReserved) . ' ' . __('maximum') . ')', '', true, 5); $inputs .= wf_Submit(__('Create')); $form = wf_Form('', 'POST', $inputs, 'glamour'); $remainsText = __('At storage') . ' ' . $this->allStorages[$storageId] . ' ' . __('remains') . ' ' . $itemRemainsStorage . ' ' . $itemtypeUnit . ' ' . $itemtypeName; $remainsInfo = $this->messages->getStyledMessage($remainsText, 'success'); if ($alreadyReserved) { $remainsInfo .= $this->messages->getStyledMessage(__('minus') . ' ' . $alreadyReserved . ' ' . __('already reserved'), 'info'); } $cells = wf_TableCell($form, '40%'); $cells .= wf_TableCell($remainsInfo, '', '', 'valign="top"'); $rows = wf_TableRow($cells, ''); $result = wf_TableBody($rows, '100%', 0, ''); } else { $result = $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('No available workers for reserve creation'), 'error'); } } else { $result = $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('No existing warehouse item types'), 'error'); } } else { $result = $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('No existing warehouse storages'), 'error'); } return ($result); } /** * Deletes existing reservation record from database * * @param int $id * * @return void */ public function reserveDelete($id) { $id = vf($id, 3); if (isset($this->allReserve[$id])) { $reserveData = $this->allReserve[$id]; if (!empty($reserveData)) { $this->reservePushLog('delete', $reserveData['storageid'], $reserveData['itemtypeid'], $reserveData['count'], $reserveData['employeeid'], $id); } $query = "DELETE from `wh_reserve` WHERE `id`='" . $id . "';"; nr_query($query); log_register('WAREHOUSE RESERVE DELETE [' . $id . ']'); } } /** * Returns reserve record editing form * * @param int $id * @param bool $hideEmployee * * @return string */ public function reserveEditForm($id, $hideEmployee = false) { $id = vf($id, 3); $result = ''; if (isset($this->allReserve[$id])) { $reserveData = $this->allReserve[$id]; $reserveStorage = $reserveData['storageid']; @$itemName = $this->allItemTypeNames[$reserveData['itemtypeid']]; @$itemData = $this->allItemTypes[$reserveData['itemtypeid']]; @$itemUnit = $this->unitTypes[$itemData['unit']]; if ($hideEmployee) { $inputs = wf_HiddenInput('editreserveemployeeid', $reserveData['employeeid']); } else { $inputs = wf_Selector('editreserveemployeeid', $this->activeEmployee, __('Worker'), $reserveData['employeeid'], true); } $inputs .= wf_TextInput('editreservecount', $itemUnit . ' ' . $itemName, $reserveData['count'], true, 5); $inputs .= wf_HiddenInput('editreserveid', $id); $inputs .= wf_Submit(__('Save')); $result = wf_Form('', 'POST', $inputs, 'glamour'); } return ($result); } /** * Drain items from some reserve. If items count less than zero - deletes reserve. * * @param int $reserveId * @param float $count * * @return void */ protected function reserveDrain($reserveId, $count) { $reserveId = vf($reserveId, 3); if (isset($this->allReserve[$reserveId])) { $reserveData = $this->allReserve[$reserveId]; $oldCount = $reserveData['count']; if (empty($oldCount)) { $oldCount = 0; } if (empty($count)) { $count = 0; } $newCount = $oldCount - $count; $newCountF = mysql_real_escape_string($newCount); $where = " WHERE `id`='" . $reserveId . "';"; if ($newCountF > 0) { simple_update_field('wh_reserve', 'count', $newCountF, $where); log_register('WAREHOUSE RESERVE DRAIN [' . $reserveId . '] COUNT `' . $newCount . '` EMPLOYEE [' . $reserveData['employeeid'] . ']'); $this->reservePushLog('update', $reserveData['storageid'], $reserveData['itemtypeid'], $newCount, $reserveData['employeeid'], $reserveId); } else { $this->reserveDelete($reserveId); } } } /** * Saves reserve changes into database * * @return void */ public function reserveSave() { if (wf_CheckPost(array('editreserveid', 'editreserveemployeeid', 'editreservecount'))) { $id = vf($_POST['editreserveid'], 3); if (isset($this->allReserve[$id])) { $reserveData = $this->allReserve[$id]; if (!empty($reserveData)) { $reserveStorage = $reserveData['storageid']; $reserveItemtypeId = $reserveData['itemtypeid']; $count = $_POST['editreservecount']; $countF = mysql_real_escape_string($count); $countF = str_replace(',', '.', $countF); $employeeId = vf($_POST['editreserveemployeeid'], 3); $where = " WHERE `id`='" . $id . "';"; $storageRemains = $this->remainsOnStorage($reserveStorage); @$itemtypeRemains = $storageRemains[$reserveItemtypeId]; if (empty($itemtypeRemains)) { $itemtypeRemains = 0; } $alreadyReserved = $this->reserveGet($reserveStorage, $reserveData['itemtypeid']); $realRemains = $itemtypeRemains - $alreadyReserved; $controlRemains = $realRemains + $reserveData['count']; if ($controlRemains >= $countF) { simple_update_field('wh_reserve', 'employeeid', $employeeId, $where); simple_update_field('wh_reserve', 'count', $countF, $where); log_register('WAREHOUSE RESERVE EDIT [' . $id . '] COUNT `' . $count . '` EMPLOYEE [' . $employeeId . ']'); $this->reservePushLog('update', $reserveStorage, $reserveItemtypeId, $count, $employeeId, $id); } else { log_register('WAREHOUSE RESERVE FAIL [' . $id . '] TO MANY COUNT `' . $count . '` EMPLOYEE [' . $employeeId . ']'); } } else { log_register('WAREHOUSE RESERVE FAIL [' . $id . '] EMPTY DATA'); } } } } /** * Returns reserve creation date extracted from log if exists * * @param int $resId * * @return string */ protected function reserveGetCreationDate($resId) { $result = __('Nothing'); if (isset($this->allReserveCreationDates[$resId])) { $result = $this->allReserveCreationDates[$resId]; } return ($result); } /** * Renders list of available reserved items sorted by Employee with some controls * * @return string */ public function reserveRenderList() { $result = ''; $printFlag = (wf_CheckGet(array('printable'))) ? true : false; if (!empty($this->allReserve)) { $columns = array( __('ID'), __('Creation date'), __('Warehouse storage'), __('Category'), __('Warehouse item type'), __('Count'), __('Worker'), __('Actions') ); $opts = '"order": [[ 0, "desc" ]]'; $callbackUrl = self::URL_ME . '&' . self::URL_RESERVE . '&reserveajlist=true'; if (ubRouting::checkGet('empidfilter')) { $callbackUrl .= '&empidfilter=' . ubRouting::get('empidfilter', 'int'); } $result = wf_JqDtLoader($columns, $callbackUrl, false, __('Reserved'), 50, $opts); } else { $result = $this->messages->getStyledMessage(__('Nothing found'), 'info'); } if ($printFlag) { //Printable report here if (!empty($this->allReserve)) { $cells = wf_TableCell(__('ID')); $cells .= wf_TableCell(__('Creation date')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item type')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Worker')); $rows = wf_TableRow($cells, 'row1'); foreach ($this->allReserve as $io => $each) { $itemTypeLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $each['itemtypeid'], @$this->allItemTypeNames[$each['itemtypeid']]); $cells = wf_TableCell($each['id']); $cells .= wf_TableCell($this->reserveGetCreationDate($each['id'])); $cells .= wf_TableCell(@$this->allStorages[$each['storageid']]); $cells .= wf_TableCell(@$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]); $cells .= wf_TableCell($itemTypeLink); $cells .= wf_TableCell($each['count'] . ' ' . @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]); $cells .= wf_TableCell(@$this->allEmployee[$each['employeeid']]); $rows .= wf_TableRow($cells, 'row5'); } $result = wf_TableBody($rows, '100%', 0, 'sortable'); } $this->reportPrintable(__('Reserved'), $result); } else { return ($result); } } /** * Renders JSON of available reserves list * * @param int $employeeId * * @return void */ public function reserveListAjaxReply($employeeId = '') { $json = new wf_JqDtHelper(); $employeeId = ubRouting::filters($employeeId, 'int'); $hideEmployee = (empty($employeeId)) ? true : false; $filtered = true; if (!empty($this->allReserve)) { foreach ($this->allReserve as $io => $each) { if ($employeeId) { if ($each['employeeid'] == $employeeId) { $filtered = true; } else { $filtered = false; } } if ($filtered) { $itemTypeLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $each['itemtypeid'], @$this->allItemTypeNames[$each['itemtypeid']]); $data[] = $each['id']; $data[] = $this->reserveGetCreationDate($each['id']); $data[] = @$this->allStorages[$each['storageid']]; $data[] = @$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]; $data[] = $itemTypeLink; $data[] = $each['count'] . ' ' . @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]; $employeeLinkUrl = self::URL_ME . '&' . self::URL_RESERVE . '&' . 'empidfilter=' . $each['employeeid']; $employeeLinkAct = wf_Link($employeeLinkUrl, @$this->allEmployee[$each['employeeid']]); $data[] = $employeeLinkAct; $actLinks = wf_JSAlert(self::URL_ME . '&' . self::URL_RESERVE . '&deletereserve=' . $each['id'], web_delete_icon(), $this->messages->getEditAlert()) . ' '; $actLinks .= wf_modalAuto(web_edit_icon(), __('Edit') . ' ' . __('Reservation'), $this->reserveEditForm($each['id'], $hideEmployee), '') . ' '; if ($each['count'] > 0) { if (cfr('WAREHOUSEOUTRESERVE')) { $outcomeUrl = self::URL_ME . '&' . self::URL_OUT . '&storageid=' . $each['storageid'] . '&outitemid=' . $each['itemtypeid'] . '&reserveid=' . $each['id']; $actLinks .= wf_Link($outcomeUrl, wf_img('skins/whoutcoming_icon.png') . ' ' . __('Outcoming'), false, ''); } } $data[] = $actLinks; $json->addRow($data); unset($data); } } } $json->getJson(); } /** * Returns employee name by its ID * * @param int $employeeId * * @return string */ public function getEmployeeName($employeeId) { $employeeId = ubRouting::filters($employeeId, 'int'); $result = ''; if (isset($this->allEmployee[$employeeId])) { $result .= $this->allEmployee[$employeeId]; } return ($result); } /** * Renders mass out employee replacement form and performs some redirects if required. * * @param int $employeeId * * @return string */ public function renderMassOutEmployyeReplaceForm($employeeId) { $result = ''; //redirect to new employee reserve if (ubRouting::checkPost(self::PROUTE_EMPREPLACE)) { $newEmpId = ubRouting::post(self::PROUTE_EMPREPLACE, 'int'); $newRoute = self::URL_ME . '&' . self::URL_RESERVE . '&massoutemployee=' . $newEmpId; if (ubRouting::checkGet('taskidpreset')) { $taskId = ubRouting::get('taskidpreset', 'int'); $newRoute .= '&taskidpreset=' . $taskId; } ubRouting::nav($newRoute); } //build some form if (!empty($this->activeEmployee)) { $inputs = wf_Selector(self::PROUTE_EMPREPLACE, $this->activeEmployee, __('Worker'), $employeeId, false) . ' '; $inputs .= wf_Submit(__('Change')); $result .= wf_Form('', 'POST', $inputs, 'glamour'); } else { $result .= $this->messages->getStyledMessage(__('No job types and employee available'), 'error'); } return ($result); } /** * Renders mass outcome form for some employeeId reserved items * * @param int $employeeId * * @return string */ public function renderMassOutForm($employeeId) { $result = ''; $employeeId = ubRouting::filters($employeeId, 'int'); $employeeInventory = array(); $form = ''; $form .= wf_FormDisabler(); if (!empty($employeeId)) { if (isset($this->allEmployee[$employeeId])) { if (!empty($this->allReserve)) { foreach ($this->allReserve as $reserveId => $reserveData) { if ($reserveData['employeeid'] == $employeeId) { $employeeInventory[$reserveId] = $reserveData; } } } if (!empty($employeeInventory)) { $result .= wf_AjaxLoader(); //destination interface $tmpDests = array(); foreach ($this->outDests as $destMark => $destName) { $tmpDests[self::URL_ME . '&' . self::URL_OUT . '&' . self::URL_AJODSELECTOR . $destMark] = $destName; } $inputs = wf_HiddenInput(self::PROUTE_DOMASSRESOUT, $employeeId); $inputs .= wf_AjaxSelectorAC('ajoutdestselcontainer', $tmpDests, __('Destination'), '', false); $inputs .= wf_AjaxContainer('ajoutdestselcontainer', '', $this->outcomindAjaxDestSelector('task')); $form .= $inputs; $form .= wf_delimiter(0); //reserves interface $cells = wf_TableCell(__('Creation date')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item type')); $cells .= wf_TableCell(__('Reserved')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Price')); $cells .= wf_TableCell(__('Notes')); $rows = wf_TableRow($cells, 'row1'); foreach ($employeeInventory as $eachInvId => $eachInvData) { $itemTypeId = $eachInvData['itemtypeid']; $itemTypeCategory = $this->allCategories[$this->allItemTypes[$itemTypeId]['categoryid']]; $itemTypeName = $this->allItemTypeNames[$itemTypeId]; $itemTypeStorageId = $this->allStorages[$eachInvData['storageid']]; $itemTypeUnit = $this->allItemTypes[$itemTypeId]['unit']; $itemTypeRecPrice = $this->getIncomeMiddlePrice($itemTypeId); $midPriceLabel = ($this->recPriceFlag) ? __('recommended') : __('middle price'); $midPriceNotice = wf_tag('abbr', false, '', 'title="' . $midPriceLabel . ': ' . $itemTypeRecPrice . '"') . '?' . wf_tag('abbr', true); $cells = wf_TableCell($this->reserveGetCreationDate($eachInvId)); $cells .= wf_TableCell($itemTypeStorageId); $cells .= wf_TableCell($itemTypeCategory); $cells .= wf_TableCell($itemTypeName); $cells .= wf_TableCell($eachInvData['count'] . ' ' . __($itemTypeUnit)); $cells .= wf_TableCell(wf_TextInput(self::PROUTE_MASSRESERVEOUT . '[' . $eachInvId . '][count]', $itemTypeUnit, '', false, 5, 'float')); $cells .= wf_TableCell(wf_TextInput(self::PROUTE_MASSRESERVEOUT . '[' . $eachInvId . '][price]', $midPriceNotice, '', false, 3, 'finance')); $defaultNotePreset = ''; $cells .= wf_TableCell(wf_TextInput(self::PROUTE_MASSRESERVEOUT . '[' . $eachInvId . '][note]', '', $defaultNotePreset, false, 15)); $rows .= wf_TableRow($cells, 'row5'); } $form .= wf_TableBody($rows, '100%', 0, 'sortable'); $form .= wf_delimiter(0); $massOutAgreement = __('I`m ready') . '. '; $massOutAgreement .= __('I also understand well that no one will correct my mistakes for me and only I bear full financial responsibility for my mistakes') . '.'; $form .= wf_CheckInput(self::PROUTE_MASSAGREEOUT, $massOutAgreement, true, false); $form .= wf_delimiter(0); $form .= wf_Submit(__('Mass outcome')); $result .= wf_Form('', 'POST', $form, ''); } else { $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('Nothing reserved for this employee'), 'error'); } } else { $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('Worker') . ' [' . $employeeId . '] ' . __('Not exists'), 'error'); } } else { $result .= $this->messages->getStyledMessage(__('Strange exeption') . ' EX_EMPLOYEEID_EMPTY', 'error'); } return ($result); } /** * Runs batch outcome operations creation based on reserve * * @return void/string on error */ public function runMassReserveOutcome() { $result = ''; $outCount = 0; if (ubRouting::checkPost(self::PROUTE_DOMASSRESOUT)) { if (ubRouting::checkPost(self::PROUTE_MASSAGREEOUT)) { if (ubRouting::checkPost(array('newoutdesttype', 'newoutdestparam', 'massoutreserves'))) { $employeeId = ubRouting::post(self::PROUTE_DOMASSRESOUT); $outDestType = ubRouting::post('newoutdesttype'); $outDestParam = ubRouting::post('newoutdestparam'); $outResArr = ubRouting::post(self::PROUTE_MASSRESERVEOUT); $curDate = curdate(); if (!empty($outResArr)) { if (is_array($outResArr)) { foreach ($outResArr as $eachReserveId => $eachReserveData) { if (isset($this->allReserve[$eachReserveId])) { if ($eachReserveData['count'] > 0) { $reserveOpts = $this->allReserve[$eachReserveId]; $storageId = $reserveOpts['storageid']; $itemtypeId = $reserveOpts['itemtypeid']; $count = $eachReserveData['count']; $price = $eachReserveData['price']; $defaultNote = ' ' . __('from reserved on') . ' ' . @$this->allEmployee[$employeeId]; $outcomeNote = (!empty($eachReserveData['note'])) ? $defaultNote . ' ' . $eachReserveData['note'] : $defaultNote; $eachOutcomeResult = $this->outcomingCreate($curDate, $outDestType, $outDestParam, $storageId, $itemtypeId, $count, $price, $outcomeNote, $eachReserveId); if (!empty($eachOutcomeResult)) { $itemtypeIssueLabel = __('Problem') . ': ' . $this->allItemTypeNames[$itemtypeId]; $result .= $this->messages->getStyledMessage($itemtypeIssueLabel, 'warning'); $result .= $eachOutcomeResult; log_register('WAREHOUSE RESMASSOUT FAIL ITEMID [' . $itemtypeId . '] COUNT `' . $count . '`'); //Saving debug log file_put_contents(self::LOG_PATH, '==================' . PHP_EOL, FILE_APPEND); file_put_contents(self::LOG_PATH, curdatetime() . PHP_EOL, FILE_APPEND); file_put_contents(self::LOG_PATH, 'GET DATA:' . PHP_EOL, FILE_APPEND); file_put_contents(self::LOG_PATH, print_r(ubRouting::rawGet(), true) . PHP_EOL, FILE_APPEND); file_put_contents(self::LOG_PATH, 'POST DATA:' . PHP_EOL, FILE_APPEND); file_put_contents(self::LOG_PATH, print_r(ubRouting::rawPost(), true) . PHP_EOL, FILE_APPEND); file_put_contents(self::LOG_PATH, 'RESERVE OPTS:' . PHP_EOL, FILE_APPEND); file_put_contents(self::LOG_PATH, print_r($reserveOpts, true) . PHP_EOL, FILE_APPEND); file_put_contents(self::LOG_PATH, 'INVOKES:' . $itemtypeIssueLabel . ' ' . strip_tags($eachOutcomeResult) . PHP_EOL, FILE_APPEND); } $outCount++; } } else { $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('Reserve') . ' [' . $eachReserveId . '] ' . __('Not exists'), 'error'); log_register('WAREHOUSE RESMASSOUT FAIL RESERVE [' . $eachReserveId . '] NOT EXISTS'); } } if ($outCount == 0) { $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('Outcoming operations') . ' - 0', 'warning'); log_register('WAREHOUSE RESMASSOUT FAIL ZERO OUTCOMES'); } } else { $result .= $this->messages->getStyledMessage(__('Something went wrong') . ' EX_CORRUPT_RESARR', 'error'); log_register('WAREHOUSE RESMASSOUT FAIL CORRUPT_RESARR'); } } else { $result .= $this->messages->getStyledMessage(__('Something went wrong') . ' EX_EMPTY_RESARR', 'error'); log_register('WAREHOUSE RESMASSOUT FAIL EMPTY_RESARR'); } } } else { $result .= $this->messages->getStyledMessage(__('You are not mentally prepared for this'), 'error'); log_register('WAREHOUSE RESMASSOUT FAIL NO_AGREEMENT'); } } return ($result); } /** * Renders printable per-employee reserves summary. * * @param int $employeeId * * @return void */ public function reportEmployeeInventrory($employeeId) { $employeeId = ubRouting::filters($employeeId, 'int'); $reportTmp = array(); $result = ''; if (!empty($employeeId)) { $filtered = true; if (!empty($this->allReserve)) { foreach ($this->allReserve as $io => $each) { if ($each['employeeid'] == $employeeId) { if (isset($reportTmp[$each['itemtypeid']])) { $reportTmp[$each['itemtypeid']] += $each['count']; } else { $reportTmp[$each['itemtypeid']] = $each['count']; } } } } if (!empty($reportTmp)) { $cells = wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item type')); $cells .= wf_TableCell(__('Expected count') . ' (' . __('Reserved') . ')'); if (ubRouting::checkGet('invprintable')) { $cells .= wf_TableCell(__('Notes')); } $rows = wf_TableRow($cells, 'row1'); foreach ($reportTmp as $itemTypeId => $count) { $cells = wf_TableCell(@$this->allCategories[$this->allItemTypes[$itemTypeId]['categoryid']]); $cells .= wf_TableCell(@$this->allItemTypeNames[$itemTypeId]); $cells .= wf_TableCell($count . ' ' . @$this->unitTypes[$this->allItemTypes[$itemTypeId]['unit']]); if (ubRouting::checkGet('invprintable')) { $cells .= wf_TableCell(''); } $rows .= wf_TableRow($cells, 'row3'); } $result .= wf_TableBody($rows, '100%', 0, 'sortable'); if (ubRouting::checkGet('invprintable')) { //printable inventory report $this->reportPrintable(__('Employee inventory') . ': ' . @$this->allEmployee[$employeeId], $result); } else { //normal renderer $inventoryUrl = self::URL_ME . '&' . self::URL_RESERVE . '&empinventory=' . $employeeId . '&invprintable=true'; $reportControls = wf_Link($inventoryUrl, web_icon_print()); show_window(__('Employee inventory') . ': ' . @$this->allEmployee[$employeeId] . ' ' . $reportControls, $result); } } else { show_info(__('Nothing to show')); } } else { show_error(__('Something went wrong') . ' EX_EMPLOYEEID_EMPTY'); } } /** * Renders json list of available reservation history log entries * * @return void */ public function reserveHistoryAjaxReply() { $json = new wf_JqDtHelper(); if (!empty($this->allReserveHistory)) { $employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached()); foreach ($this->allReserveHistory as $io => $each) { $operationType = ''; $administratorName = (isset($employeeLogins[$each['admin']])) ? $employeeLogins[$each['admin']] : $each['admin']; switch ($each['type']) { case 'create': $operationType = __('Created'); break; case 'update': $operationType = __('Updated'); break; case 'delete': $operationType = __('Deleted'); break; } if (!empty($each['resid'])) { $resIdLabel = __('Reserve') . '@' . $each['resid']; } else { $resIdLabel = ''; } $data[] = $resIdLabel; $data[] = $each['date']; $data[] = $operationType; $data[] = @$this->allStorages[$each['storageid']]; $data[] = @$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]; $data[] = wf_link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $each['itemtypeid'], @$this->allItemTypeNames[$each['itemtypeid']]); $data[] = $each['count'] . ' ' . @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]; $data[] = @$this->allEmployee[$each['employeeid']]; $data[] = $administratorName; $json->addRow($data); unset($data); } } $json->getJson(); } /** * Returns array of available administrators as login=>name * * @return array */ protected function getAdminNames() { $result = array(); $all = rcms_scandir(USERS_PATH); if (!empty($all)) { $employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached()); foreach ($all as $each) { $administratorName = (isset($employeeLogins[$each])) ? $employeeLogins[$each] : $each; $result[$each] = $administratorName; } } return ($result); } /** * Renders reserve history print filtering form * * @return string */ public function reserveHistoryFilterForm() { $result = ''; $adminNames = array('' => '-'); $adminNames += $this->getAdminNames(); $inputs = __('From') . ' ' . wf_DatePickerPreset('reshistfilterfrom', curdate()) . ' '; $inputs .= __('To') . ' ' . wf_DatePickerPreset('reshistfilterto', curdate()) . ' '; $inputs .= wf_Selector('reshistfilteremployeeid', $this->activeEmployee, __('Worker'), '', false); $inputs .= wf_Selector('reshistfilteradminlogin', $adminNames, __('Admin'), '', false); $inputs .= wf_Submit(__('Print')); $result .= wf_Form('', 'POST', $inputs, 'glamour'); return ($result); } /** * Renders printable report of reserve operations history * * @return void */ public function reserveHistoryPrintFiltered() { $result = ''; if (wf_CheckPost(array('reshistfilterfrom', 'reshistfilterto', 'reshistfilteremployeeid'))) { $dateFrom = $_POST['reshistfilterfrom']; $dateTo = $_POST['reshistfilterto']; $employeeId = vf($_POST['reshistfilteremployeeid'], 3); $adminLogin = @$_POST['reshistfilteradminlogin']; if (zb_checkDate($dateFrom) and zb_checkDate($dateTo)) { $dateFrom = $dateFrom . ' 00:00:00'; $dateTo = $dateTo . ' 23:59:59'; $dateFrom = strtotime($dateFrom); $dateTo = strtotime($dateTo); if (!empty($this->allReserveHistory)) { $employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached()); $cells = wf_TableCell(__('ID')); $cells .= wf_TableCell(__('Date')); $cells .= wf_TableCell(__('Type')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item type')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Employee')); $cells .= wf_TableCell(__('Admin')); $rows = wf_TableRow($cells, 'row1'); foreach ($this->allReserveHistory as $io => $each) { $operationDate = strtotime($each['date']); $filteredFlag = false; //data filtering if ($employeeId == $each['employeeid']) { if ($operationDate >= $dateFrom and $operationDate <= $dateTo) { $filteredFlag = true; } } //optional admin filtering if (!empty($adminLogin)) { if ($filteredFlag) { if ($each['admin'] != $adminLogin) { $filteredFlag = false; } } } //report assembly if ($filteredFlag) { $operationType = ''; $administratorName = (isset($employeeLogins[$each['admin']])) ? $employeeLogins[$each['admin']] : $each['admin']; switch ($each['type']) { case 'create': $operationType = __('Created'); break; case 'update': $operationType = __('Updated'); break; case 'delete': $operationType = __('Deleted'); break; } if (!empty($each['resid'])) { $resIdLabel = __('Reserve') . '@' . $each['resid']; } else { $resIdLabel = ''; } $cells = wf_TableCell($resIdLabel); $cells .= wf_TableCell($each['date']); $cells .= wf_TableCell($operationType); $cells .= wf_TableCell(@$this->allStorages[$each['storageid']]); $cells .= wf_TableCell(@$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]); $cells .= wf_TableCell(@$this->allItemTypeNames[$each['itemtypeid']]); $cells .= wf_TableCell($each['count'] . ' ' . @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]); $cells .= wf_TableCell(@$this->allEmployee[$each['employeeid']]); $cells .= wf_TableCell($administratorName); $rows .= wf_TableRow($cells, 'row3'); } } $result .= wf_TableBody($rows, '100%', 0, 'sortable'); $result .= wf_tag('br'); $result .= __('Signature') . '______________________'; $this->reportPrintable(__('Act of issuance of goods from the warehouse'), $result); } else { show_warning(__('Nothing to show')); } } else { show_error(__('Wrong date format')); } } } /** * Renders reservation history log * * @return string */ public function reserveRenderHistory() { $result = ''; if (!empty($this->allReserveHistory)) { $colums = array('ID', 'Date', 'Type', 'Warehouse storage', 'Category', 'Warehouse item type', 'Count', 'Employee', 'Admin'); $opts = '"order": [[ 0, "desc" ]]'; $ajaxUrl = self::URL_ME . '&' . self::URL_RESERVE . '&reshistajlist=true'; $result .= wf_JqDtLoader($colums, $ajaxUrl, false, __('Reserve'), 50, $opts); if (!empty($this->allReserveHistory)) { $result .= wf_delimiter(); $result .= $this->reserveHistoryFilterForm(); } } else { $result = $this->messages->getStyledMessage(__('Nothing found'), 'info'); } return ($result); } /** * Returns cetegory creation form * * @return string */ public function categoriesCreateForm() { $result = ''; $inputs = wf_TextInput('newcategory', __('Name'), '', false, 20); $inputs .= wf_Submit(__('Create')); $result = wf_Form(self::URL_ME . '&' . self::URL_CATEGORIES, 'POST', $inputs, 'glamour'); return ($result); } /** * Returns cetegory edit form * * @param int $categoryId * * @return string */ protected function categoriesEditForm($categoryId) { $result = ''; $inputs = wf_TextInput('editcategoryname', __('Name'), $this->allCategories[$categoryId], false, 20); $inputs .= wf_HiddenInput('editcategoryid', $categoryId); $inputs .= wf_Submit(__('Save')); $result = wf_Form(self::URL_ME . '&' . self::URL_CATEGORIES, 'POST', $inputs, 'glamour'); return ($result); } /** * Renders list of available categories with some controls * * @return string */ public function categoriesRenderList() { $result = ''; $cells = wf_TableCell(__('ID')); $cells .= wf_TableCell(__('Name')); $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'row1'); if (!empty($this->allCategories)) { foreach ($this->allCategories as $id => $name) { $cells = wf_TableCell($id); $cells .= wf_TableCell($name); $actLinks = wf_JSAlert(self::URL_ME . '&' . self::URL_CATEGORIES . '&deletecategory=' . $id, web_delete_icon(), $this->messages->getDeleteAlert()) . ' '; $actLinks .= wf_modalAuto(web_edit_icon(), __('Edit'), $this->categoriesEditForm($id)); $cells .= wf_TableCell($actLinks); $rows .= wf_TableRow($cells, 'row3'); } } $result = wf_TableBody($rows, '100%', 0, 'sortable'); return ($result); } /** * Creates new category in database * * @param string $name * * @return void */ public function categoriesCreate($name) { $nameF = mysql_real_escape_string($name); $query = "INSERT INTO `wh_categories` (`id`,`name`) VALUES (NULL,'" . $nameF . "');"; nr_query($query); $newId = simple_get_lastid('wh_categories'); log_register('WAREHOUSE CATEGORY ADD [' . $newId . '] `' . $name . '`'); } /** * Check is category used by some items? * * @param int $categoryId * * @return bool */ protected function categoryProtected($categoryId) { $categoryId = vf($categoryId, 3); $result = false; if (!empty($this->allItemTypes)) { foreach ($this->allItemTypes as $io => $each) { if ($each['categoryid'] == $categoryId) { $result = true; break; } } } return ($result); } /** * Deletes existging category from database * * @param int $categoryId * * @return bool */ public function categoriesDelete($categoryId) { if (isset($this->allCategories[$categoryId])) { if (!$this->categoryProtected($categoryId)) { $query = "DELETE from `wh_categories` WHERE `id`='" . $categoryId . "';"; nr_query($query); log_register('WAREHOUSE CATEGORY DELETE [' . $categoryId . ']'); $result = true; } else { $result = false; } } else { $result = false; } return ($result); } /** * Saves category changes in database by data recieved from form * * @return void */ public function categoriesSave() { if (wf_CheckPost(array('editcategoryname', 'editcategoryid'))) { $categoryId = vf($_POST['editcategoryid']); if (isset($this->allCategories[$categoryId])) { simple_update_field('wh_categories', 'name', $_POST['editcategoryname'], "WHERE `id`='" . $categoryId . "'"); log_register('WAREHOUSE CATEGORY EDIT [' . $categoryId . '] `' . $_POST['editcategoryname'] . '`'); } else { log_register('WAREHOUSE CATEGORY EDIT FAIL [' . $categoryId . '] NO_EXISTING'); } } } /** * Renders default back control * * @param string $url Optional URL * * @return void */ public function backControl($url = '') { if (empty($url)) { show_window('', wf_BackLink(self::URL_ME)); } else { show_window('', wf_BackLink($url)); } } /** * Renders control panel for whole module * * @return string */ public function renderPanel() { $result = ''; $result .= wf_Link(self::URL_ME . '&' . self::URL_REPORTS . '&' . 'totalremains=true', wf_img_sized('skins/whstorage_icon.png') . ' ' . __('The remains in all storages'), false, 'ubButton'); if (cfr('WAREHOUSEIN')) { $result .= wf_Link(self::URL_ME . '&' . self::URL_IN, wf_img_sized('skins/whincoming_icon.png') . ' ' . __('Incoming operations'), false, 'ubButton'); } if ((cfr('WAREHOUSEOUT')) or (cfr('WAREHOUSEOUTRESERVE'))) { $result .= wf_Link(self::URL_ME . '&' . self::URL_OUT, wf_img_sized('skins/whoutcoming_icon.png') . ' ' . __('Outcoming operations'), false, 'ubButton'); } if (cfr('WAREHOUSERESERVE')) { $result .= wf_Link(self::URL_ME . '&' . self::URL_RESERVE, wf_img('skins/whreservation.png') . ' ' . __('Reserved'), false, 'ubButton'); } if (cfr('WAREHOUSEDIR')) { $dirControls = wf_Link(self::URL_ME . '&' . self::URL_CATEGORIES, wf_img_sized('skins/categories_icon.png') . ' ' . __('Warehouse categories'), false, 'ubButton'); $dirControls .= wf_Link(self::URL_ME . '&' . self::URL_ITEMTYPES, wf_img_sized('skins/folder_icon.png') . ' ' . __('Warehouse item types'), false, 'ubButton'); $dirControls .= wf_Link(self::URL_ME . '&' . self::URL_STORAGES, wf_img_sized('skins/whstorage_icon.png') . ' ' . __('Warehouse storages'), false, 'ubButton'); $dirControls .= wf_Link(self::URL_ME . '&' . self::URL_CONTRACTORS, wf_img_sized('skins/whcontractor_icon.png') . ' ' . __('Contractors'), false, 'ubButton'); $result .= wf_modalAuto(web_icon_extended() . ' ' . __('Directories'), __('Directories'), $dirControls, 'ubButton'); } if (cfr('WAREHOUSEREPORTS')) { $reportControls = wf_Link(self::URL_ME . '&' . self::URL_REPORTS . '&calendarops=true', wf_img_sized('skins/icon_calendar.gif') . ' ' . __('Operations in the context of time'), false, 'ubButton'); $reportControls .= wf_Link(self::URL_ME . '&' . self::URL_REPORTS . '&dateremains=true', wf_img_sized('skins/icon_batman.png') . ' ' . __('Date remains'), false, 'ubButton'); $reportControls .= wf_Link(self::URL_ME . '&' . self::URL_REPORTS . '&storagesremains=true', wf_img_sized('skins/icon_print.png') . ' ' . __('The remains in the warehouse storage'), false, 'ubButton'); $reportControls .= wf_Link(self::URL_ME . '&' . self::URL_REPORTS . '&itemtypeoutcomes=true', wf_img_sized('skins/sales.png') . ' ' . __('Sales'), false, 'ubButton'); $reportControls .= wf_Link(self::URL_ME . '&' . self::URL_REPORTS . '&purchases=true', wf_img_sized('skins/shopping_cart_small.png') . ' ' . __('Purchases'), false, 'ubButton'); $reportControls .= wf_Link(self::URL_ME . '&' . self::URL_REPORTS . '&contractorincomes=true', wf_img_sized('skins/whcontractor_icon.png') . ' ' . __('Contractor'), false, 'ubButton'); $reportControls .= wf_Link(WHSales::URL_ME, wf_img_sized('skins/salesreportsmall.png') . ' ' . __('Sales report'), false, 'ubButton'); if (@$this->altCfg['WAREHOUSE_RETURNS_ENABLED']) { $reportControls .= wf_Link(self::URL_ME . '&' . self::URL_REPORTS . '&returns=true', wf_img_sized('skins/return.png') . ' ' . __('Returns'), false, 'ubButton'); } $result .= wf_modalAuto(wf_img('skins/ukv/report.png') . ' ' . __('Reports'), __('Reports'), $reportControls, 'ubButton'); } return ($result); } /** * Returns item types creation form * * @return string */ public function itemtypesCreateForm() { $result = ''; if (!empty($this->allCategories)) { $inputs = wf_Selector('newitemtypecetegoryid', $this->allCategories, __('Category'), '', true); $inputs .= wf_TextInput('newitemtypename', __('Name'), '', true, '20'); $inputs .= wf_Selector('newitemtypeunit', $this->unitTypes, __('Units'), '', true); $inputs .= wf_TextInput('newitemtypereserve', __('Desired reserve'), '', true, 5); $inputs .= wf_Submit(__('Create')); $result = wf_Form(self::URL_ME . '&' . self::URL_ITEMTYPES, 'POST', $inputs, 'glamour'); } else { $result = $this->messages->getStyledMessage(__('No existing categories'), 'warning'); } return ($result); } /** * Returns item types editing form * * @return string */ public function itemtypesEditForm($itemtypeId) { $result = ''; if (isset($this->allItemTypes[$itemtypeId])) { $itemtypeData = $this->allItemTypes[$itemtypeId]; $inputs = wf_Selector('edititemtypecetegoryid', $this->allCategories, __('Category'), $itemtypeData['categoryid'], true); $inputs .= wf_TextInput('edititemtypename', __('Name'), $itemtypeData['name'], true, '20'); $inputs .= wf_Selector('edititemtypeunit', $this->unitTypes, __('Units'), $itemtypeData['unit'], true); $inputs .= wf_TextInput('edititemtypereserve', __('Desired reserve'), $itemtypeData['reserve'], true, 5); $inputs .= wf_HiddenInput('edititemtypeid', $itemtypeId); $inputs .= wf_Submit(__('Save')); $result = wf_Form(self::URL_ME . '&' . self::URL_ITEMTYPES, 'POST', $inputs, 'glamour'); } return ($result); } /** * Saves item type changes in database by data recieved from form * * @return void */ public function itemtypesSave() { if (wf_CheckPost(array('edititemtypeid', 'edititemtypename', 'edititemtypecetegoryid', 'edititemtypeunit'))) { $itemtypeId = vf($_POST['edititemtypeid']); if (isset($this->allItemTypes[$itemtypeId])) { $nameF = $_POST['edititemtypename']; $nameF = str_replace('"', '``', $nameF); $nameF = str_replace("'", '`', $nameF); $where = " WHERE `id`='" . $itemtypeId . "'"; simple_update_field('wh_itemtypes', 'categoryid', $_POST['edititemtypecetegoryid'], $where); simple_update_field('wh_itemtypes', 'name', $nameF, $where); simple_update_field('wh_itemtypes', 'unit', $_POST['edititemtypeunit'], $where); if (isset($_POST['edititemtypereserve'])) { $unit = str_replace(',', '.', $_POST['edititemtypereserve']); simple_update_field('wh_itemtypes', 'reserve', $unit, $where); } log_register('WAREHOUSE ITEMTYPES EDIT [' . $itemtypeId . '] `' . $_POST['edititemtypename'] . '`'); } else { log_register('WAREHOUSE ITEMTYPES EDIT FAIL [' . $itemtypeId . '] NO_EXISTING'); } } } /** * Creates new items type * * @param int $categoryid * @param string $name * @param string $unit * @param float $reserve * * @return void */ public function itemtypesCreate($categoryid, $name, $unit, $reserve = 0) { $categoryid = vf($categoryid, 3); if (isset($this->allCategories[$categoryid])) { $nameF = mysql_real_escape_string($name); $nameF = str_replace('"', '``', $nameF); $nameF = str_replace("'", '`', $nameF); $unit = mysql_real_escape_string($unit); $reserve = str_replace(',', '.', $reserve); $reserve = str_replace('-', '', $reserve); $reserve = mysql_real_escape_string($reserve); $query = "INSERT INTO `wh_itemtypes` (`id`,`categoryid`,`name`,`unit`,`reserve`) VALUES " . "(NULL,'" . $categoryid . "','" . $nameF . "','" . $unit . "','" . $reserve . "')"; nr_query($query); $newId = simple_get_lastid('wh_itemtypes'); log_register('WAREHOUSE ITEMTYPES CREATE [' . $newId . '] `' . $name . '`'); } else { log_register('WAREHOUSE ITEMTYPES CREATE FAIL NO_CATEGORY'); } } /** * Renders of available warehouse item types * * @return string */ public function itemtypesRenderList() { $result = ''; $cells = wf_TableCell(__('ID')); $cells .= wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Name')); $cells .= wf_TableCell(__('Units')); $cells .= wf_TableCell(__('Reserve')); $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'row1'); $photoStorageEnabled = ($this->altCfg['PHOTOSTORAGE_ENABLED']) ? true : false; if ($photoStorageEnabled) { $photoStorage = new PhotoStorage(self::PHOTOSTORAGE_SCOPE, 'nope'); } if (!empty($this->allItemTypes)) { $itemtypesList = $this->allItemTypes; krsort($itemtypesList); //default order from newer to older instead of order by name foreach ($itemtypesList as $io => $each) { $itemTypeLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $each['id'], $each['name']); $cells = wf_TableCell($each['id']); $cells .= wf_TableCell(@$this->allCategories[$each['categoryid']]); $cells .= wf_TableCell($itemTypeLink); $cells .= wf_TableCell(@$this->unitTypes[$each['unit']]); $cells .= wf_TableCell($each['reserve']); $actLinks = wf_JSAlert(self::URL_ME . '&' . self::URL_ITEMTYPES . '&deleteitemtype=' . $each['id'], web_delete_icon(), $this->messages->getDeleteAlert()); //commented due performance issues on clientside rendering //$actLinks .= wf_modalAuto(web_edit_icon(), __('Edit'), $this->itemtypesEditForm($each['id']), ''); $actLinks .= wf_JSAlert(self::URL_ME . '&' . self::URL_ITEMTYPES . '&edititemtype=' . $each['id'], web_edit_icon(), $this->messages->getEditAlert()); if ($photoStorageEnabled) { $photostorageIcon = 'photostorage.png'; $itemIdImageCount = $photoStorage->getImagesCount($each['id']); $photostorageUrl = '?module=photostorage&scope=' . self::PHOTOSTORAGE_SCOPE . '&itemid=' . $each['id'] . '&mode=list'; $photostorageCtrlLabel = __('Upload images'); if ($itemIdImageCount > 0) { $photostorageIcon = 'photostorage_green.png'; $photostorageCtrlLabel .= ' (' . $itemIdImageCount . ')'; } $photostorageControl = ' ' . wf_Link($photostorageUrl, wf_img_sized('skins/' . $photostorageIcon, $photostorageCtrlLabel, '16', '16'), false); } else { $photostorageControl = ''; } $actLinks .= $photostorageControl; $cells .= wf_TableCell($actLinks); $rows .= wf_TableRow($cells, 'row5'); } } $result = wf_TableBody($rows, '100%', 0, 'sortable'); return ($result); } /** * Checks is itemtype protected by some existing operations? * * @param type $itemtypeId * @return bool */ protected function itemtypeProtected($itemtypeId) { $itemtypeId = vf($itemtypeId, 3); $result = false; if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { if ($each['itemtypeid'] == $itemtypeId) { $result = true; break; } } } return ($result); } /** * Deletes items type by its ID * * * @param int $itemtypeId * * @return bool */ public function itemtypesDelete($itemtypeId) { $itemtypeId = vf($itemtypeId, 3); if (!$this->itemtypeProtected($itemtypeId)) { $query = "DELETE from `wh_itemtypes` WHERE `id`='" . $itemtypeId . "';"; nr_query($query); log_register('WAREHOUSE ITEMTYPES DELETE [' . $itemtypeId . ']'); $result = true; } else { $result = false; } return ($result); } /** * Returns itemtype name by its ID * * @param int $itemtypeId * @return string */ public function itemtypeGetName($itemtypeId) { $itemtypeId = vf($itemtypeId, 3); $result = ''; if (isset($this->allItemTypeNames[$itemtypeId])) { $result = $this->allItemTypeNames[$itemtypeId]; } return ($result); } /** * Returns item type count unit * * @param int $itemtypeId * * @return string */ public function itemtypeGetUnit($itemtypeId) { $itemtypeId = vf($itemtypeId, 3); $result = ''; $result = @$this->unitTypes[$this->allItemTypes[$itemtypeId]['unit']]; return ($result); } /** * Returns item type count unit * * @param int $itemtypeId * * @return string */ public function itemtypeGetCategory($itemtypeId) { $itemtypeId = vf($itemtypeId, 3); $result = ''; $result = @$this->allCategories[$this->allItemTypes[$itemtypeId]['categoryid']]; return ($result); } /** * Returns storage creation form * * @return string */ public function storagesCreateForm() { $result = ''; $inputs = wf_TextInput('newstorage', __('Name'), '', false, 20); $inputs .= wf_Submit(__('Create')); $result = wf_Form(self::URL_ME . '&' . self::URL_STORAGES, 'POST', $inputs, 'glamour'); return ($result); } /** * Creates new storage in database * * @param string $name * * @return void */ public function storagesCreate($name) { $nameF = mysql_real_escape_string($name); $query = "INSERT INTO `wh_storages` (`id`,`name`) VALUES (NULL,'" . $nameF . "');"; nr_query($query); $newId = simple_get_lastid('wh_storages'); log_register('WAREHOUSE STORAGES ADD [' . $newId . '] `' . $name . '`'); } /** * Check is storage used by some incoming operations? * * @param int $storageId * * @return bool */ protected function storageProtected($storageId) { $storageId = vf($storageId, 3); $result = false; if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { if ($each['storageid'] == $storageId) { $result = true; break; } } } return ($result); } /** * Returns storage name by its ID * * @param int $storageId * @return string */ public function storageGetName($storageId) { $storageId = vf($storageId, 3); $result = ''; if (isset($this->allStorages[$storageId])) { $result = $this->allStorages[$storageId]; } return ($result); } /** * Deletes existing storage from database * * @param int $storageId * * @return bool */ public function storagesDelete($storageId) { $storageId = vf($storageId); if (isset($this->allStorages[$storageId])) { if (!$this->storageProtected($storageId)) { $query = "DELETE from `wh_storages` WHERE `id`='" . $storageId . "';"; nr_query($query); log_register('WAREHOUSE STORAGES DELETE [' . $storageId . ']'); $result = true; } else { $result = false; } } else { $result = false; } return ($result); } /** * Returns storages edit form * * @param int $storageId * * @return string */ protected function storagesEditForm($storageId) { $result = ''; $inputs = wf_TextInput('editstoragename', __('Name'), $this->allStorages[$storageId], false, 20); $inputs .= wf_HiddenInput('editstorageid', $storageId); $inputs .= wf_Submit(__('Save')); $result = wf_Form(self::URL_ME . '&' . self::URL_STORAGES, 'POST', $inputs, 'glamour'); return ($result); } /** * Saves storage changes in database by data recieved from form * * @return void */ public function storagesSave() { if (wf_CheckPost(array('editstoragename', 'editstorageid'))) { $storageId = vf($_POST['editstorageid']); if (isset($this->allStorages[$storageId])) { simple_update_field('wh_storages', 'name', $_POST['editstoragename'], "WHERE `id`='" . $storageId . "'"); log_register('WAREHOUSE STORAGE EDIT [' . $storageId . '] `' . $_POST['editstoragename'] . '`'); } else { log_register('WAREHOUSE STORAGE EDIT FAIL [' . $storageId . '] NO_EXISTING'); } } } /** * Renders list of available storages with some controls * * @return string */ public function storagesRenderList() { $result = ''; $cells = wf_TableCell(__('ID')); $cells .= wf_TableCell(__('Name')); $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'row1'); if (!empty($this->allStorages)) { foreach ($this->allStorages as $id => $name) { $cells = wf_TableCell($id); $cells .= wf_TableCell($name); $actLinks = wf_JSAlert(self::URL_ME . '&' . self::URL_STORAGES . '&deletestorage=' . $id, web_delete_icon(), $this->messages->getDeleteAlert()) . ' '; $actLinks .= wf_modalAuto(web_edit_icon(), __('Edit'), $this->storagesEditForm($id)); $cells .= wf_TableCell($actLinks); $rows .= wf_TableRow($cells, 'row3'); } } $result = wf_TableBody($rows, '100%', 0, 'sortable'); return ($result); } /** I count the falling tears They fall before my eyes Seems like a thousand years Since we broke the ties I call you on the phone But never get a rise So sit there all alone It's time you realize */ /** * Returns contractor creation form * * @return string */ public function contractorsCreateForm() { $result = ''; $inputs = wf_TextInput('newcontractor', __('Name'), '', false, 20); $inputs .= wf_Submit(__('Create')); $result = wf_Form(self::URL_ME . '&' . self::URL_CONTRACTORS, 'POST', $inputs, 'glamour'); return ($result); } /** * Creates new contractor in database * * @param string $name * * @return void */ public function contractorCreate($name) { $nameF = mysql_real_escape_string($name); $query = "INSERT INTO `wh_contractors` (`id`,`name`) VALUES (NULL,'" . $nameF . "');"; nr_query($query); $newId = simple_get_lastid('wh_contractors'); log_register('WAREHOUSE CONTRACTORS ADD [' . $newId . '] `' . $name . '`'); } /** * Check is contractor used by some incoming operations? * * @param int $contractorId * * @return bool */ protected function contractorProtected($contractorId) { $contractorId = vf($contractorId, 3); $result = false; if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { if ($each['contractorid'] == $contractorId) { $result = true; break; } } } return ($result); } /** * Deletes existing contractor from database * * @param int $contractorId * * @return bool */ public function contractorsDelete($contractorId) { $contractorId = vf($contractorId); if (isset($this->allContractors[$contractorId])) { if (!$this->contractorProtected($contractorId)) { $query = "DELETE from `wh_contractors` WHERE `id`='" . $contractorId . "';"; nr_query($query); log_register('WAREHOUSE CONTRACTORS DELETE [' . $contractorId . ']'); $result = true; } else { $result = false; } } else { $result = false; } return ($result); } /** * Returns contractors edit form * * @param int $contractorId * * @return string */ protected function contractorsEditForm($contractorId) { $result = ''; $inputs = wf_TextInput('editcontractorname', __('Name'), $this->allContractors[$contractorId], false, 20); $inputs .= wf_HiddenInput('editcontractorid', $contractorId); $inputs .= wf_Submit(__('Save')); $result = wf_Form(self::URL_ME . '&' . self::URL_CONTRACTORS, 'POST', $inputs, 'glamour'); return ($result); } /** * Saves contractor changes in database by data recieved from form * * @return void */ public function contractorsSave() { if (wf_CheckPost(array('editcontractorname', 'editcontractorid'))) { $contractorId = vf($_POST['editcontractorid'], 3); if (isset($this->allContractors[$contractorId])) { simple_update_field('wh_contractors', 'name', $_POST['editcontractorname'], "WHERE `id`='" . $contractorId . "'"); log_register('WAREHOUSE CONTRACTORS EDIT [' . $contractorId . '] `' . $_POST['editcontractorname'] . '`'); } else { log_register('WAREHOUSE CONTRACTORS EDIT FAIL [' . $contractorId . '] NO_EXISTING'); } } } /** * Renders list of available contractors with some controls * * @return string */ public function contractorsRenderList() { $result = ''; $cells = wf_TableCell(__('ID')); $cells .= wf_TableCell(__('Name')); $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'row1'); if (!empty($this->allContractors)) { foreach ($this->allContractors as $id => $name) { $cells = wf_TableCell($id); $cells .= wf_TableCell($name); $actLinks = wf_JSAlert(self::URL_ME . '&' . self::URL_CONTRACTORS . '&deletecontractor=' . $id, web_delete_icon(), $this->messages->getDeleteAlert()) . ' '; $actLinks .= wf_modalAuto(web_edit_icon(), __('Edit'), $this->contractorsEditForm($id)); $cells .= wf_TableCell($actLinks); $rows .= wf_TableRow($cells, 'row3'); } } $result = wf_TableBody($rows, '100%', 0, 'sortable'); return ($result); } /** * Performs itemtypes per category filtering. Returns array id=>name * * @param int $categoryId * @return array */ protected function itemtypesFilterCategory($categoryId) { $result = array(); if (!empty($this->allItemTypes)) { foreach ($this->allItemTypes as $io => $each) { if ($each['categoryid'] == $categoryId) { $result[$each['id']] = $each['name']; } } } return ($result); } /** * Returns itemtype selector filtered by category * * @param string $name * @param int $categoryId * @return string */ public function itemtypesCategorySelector($name, $categoryId) { $result = ''; $searchableFlag = $this->altCfg['WAREHOUSE_INCOP_SEARCHBL']; $categoryItemtypes = $this->itemtypesFilterCategory($categoryId); if ($searchableFlag) { $result = wf_SelectorSearchable($name, $categoryItemtypes, __('Warehouse item types'), '', false); } else { $result = wf_Selector($name, $categoryItemtypes, __('Warehouse item types'), '', false); } if (cfr('WAREHOUSEDIR')) { $result .= wf_Link(self::URL_ME . '&' . self::URL_ITEMTYPES, wf_img_sized('skins/folder_icon.png', '', '10', '10'), false); } return ($result); } /** * Returns incoming operation creation form * * @return string */ public function incomingCreateForm() { if ((!empty($this->allItemTypes)) and (!empty($this->allCategories)) and (!empty($this->allContractors)) and (!empty($this->allStorages))) { $searchableFlag = $this->altCfg['WAREHOUSE_INCOP_SEARCHBL']; //ajax selector URL-s preprocessing $tmpCat = array(); $firstCateKey = key($this->allCategories); foreach ($this->allCategories as $categoryId => $categoryName) { $tmpCat[self::URL_ME . '&' . self::URL_IN . '&' . self::URL_AJITSELECTOR . $categoryId] = $categoryName; } $result = wf_AjaxLoader(); $inputs = wf_DatePickerPreset('newindate', curdate()); $inputs .= wf_tag('br'); if ($searchableFlag) { $inputs .= wf_AjaxSelectorSearchableAC('ajItemtypesContainer', $tmpCat, __('Warehouse categories'), '', false); } else { $inputs .= wf_AjaxSelectorAC('ajItemtypesContainer', $tmpCat, __('Warehouse categories'), '', false); } if (cfr('WAREHOUSEDIR')) { $inputs .= wf_Link(self::URL_ME . '&' . self::URL_CATEGORIES, wf_img_sized('skins/categories_icon.png', '', '10', '10'), false); } $inputs .= wf_tag('br'); $inputs .= wf_AjaxContainer('ajItemtypesContainer', '', $this->itemtypesCategorySelector('newinitemtypeid', $firstCateKey)); if ($searchableFlag) { $inputs .= wf_SelectorSearchable('newincontractorid', $this->allContractors, __('Contractor'), '', false); } else { $inputs .= wf_Selector('newincontractorid', $this->allContractors, __('Contractor'), '', false); } if (cfr('WAREHOUSEDIR')) { $inputs .= wf_Link(self::URL_ME . '&' . self::URL_CONTRACTORS, wf_img_sized('skins/whcontractor_icon.png', '', '10', '10'), false); } $inputs .= wf_tag('br'); if ($searchableFlag) { $inputs .= wf_SelectorSearchable('newinstorageid', $this->allStorages, __('Warehouse storage'), '', false); } else { $inputs .= wf_Selector('newinstorageid', $this->allStorages, __('Warehouse storage'), '', false); } if (cfr('WAREHOUSEDIR')) { $inputs .= wf_Link(self::URL_ME . '&' . self::URL_STORAGES, wf_img_sized('skins/whstorage_icon.png', '', '10', '10'), false); } $inputs .= wf_tag('br'); $inputs .= wf_TextInput('newincount', __('Count'), '', false, 5, 'float'); $inputs .= wf_tag('br'); $inputs .= wf_TextInput('newinprice', __('Price per unit'), '', false, 5, 'finance'); $inputs .= wf_tag('br'); $inputs .= wf_TextInput('newinbarcode', __('Barcode'), '', false, 15); $inputs .= wf_tag('br'); $inputs .= wf_TextInput('newinnotes', __('Notes'), '', false, 30); $inputs .= wf_tag('br'); $inputs .= wf_Submit(__('Create')); $result .= wf_Form(self::URL_ME . '&' . self::URL_IN, 'POST', $inputs, 'glamour'); } else { $result = $this->messages->getStyledMessage(__('You did not fill all the necessary directories'), 'error'); } return ($result); } /** * Creates new incoming operation in database * * @param string $date * @param int $itemtypeid * @param int $contractorid * @param int $storageid * @param float $count * @param float $price * @param string $barcode * @param string $notes * * @return void */ public function incomingCreate($date, $itemtypeid, $contractorid, $storageid, $count, $price, $barcode, $notes) { $dateF = mysql_real_escape_string($date); $itemtypeid = vf($itemtypeid, 3); $contractorid = vf($contractorid, 3); $storageid = vf($storageid, 3); $countF = str_replace(',', '.', $count); $countF = str_replace('-', '', $countF); $countF = mysql_real_escape_string($countF); $priceF = str_replace(',', '.', $price); $priceF = mysql_real_escape_string($priceF); $notes = mysql_real_escape_string($notes); $barcode = mysql_real_escape_string($barcode); $admin = mysql_real_escape_string(whoami()); $query = "INSERT INTO `wh_in` (`id`, `date`, `itemtypeid`, `contractorid`, `count`, `barcode`, `price`, `storageid`, `notes`,`admin`) " . "VALUES (NULL, '" . $dateF . "', '" . $itemtypeid . "', '" . $contractorid . "', '" . $countF . "', '" . $barcode . "', '" . $priceF . "', '" . $storageid . "', '" . $notes . "','" . $admin . "');"; nr_query($query); $newId = simple_get_lastid('wh_in'); log_register('WAREHOUSE INCOME CREATE [' . $newId . '] ITEM [' . $itemtypeid . '] COUNT `' . $count . '` PRICE `' . $price . '`'); } /** * Returns income operations list available at storages * * @return string */ public function incomingOperationsList() { $result = ''; if (!empty($this->allIncoming)) { $opts = '"order": [[ 0, "desc" ]]'; $columns = array('ID', 'Date', 'Category', 'Warehouse item types', 'Count', 'Price per unit', 'Sum', 'Warehouse storage', 'Notes', 'Actions'); $result = wf_JqDtLoader($columns, self::URL_ME . '&' . self::URL_IN . '&' . self::URL_INAJLIST, false, 'Incoming operations', 50, $opts); } else { $result = $this->messages->getStyledMessage(__('Nothing found'), 'warning'); } return ($result); } /** * Returns JQuery datatables reply for incoming operations list * * @return string */ public function incomingListAjaxReply() { $json = new wf_JqDtHelper(); if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { $actLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showinid=' . $each['id'], wf_img_sized('skins/whincoming_icon.png', '', '10', '10') . ' ' . __('Show')); $data[] = $each['id']; $data[] = $each['date']; $data[] = @$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]; $data[] = wf_link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $each['itemtypeid'], $this->allItemTypeNames[$each['itemtypeid']]); $data[] = $each['count'] . ' ' . @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]; $data[] = $each['price']; $data[] = round($each['price'] * $each['count'], 2); $data[] = @$this->allStorages[$each['storageid']]; $data[] = $each['notes']; $data[] = $actLink; $json->addRow($data); unset($data); } } $json->getJson(); } /** * Returns default contol for QR code view interface * * @param string $type * @param int $id * @return string */ protected function qrControl($type, $id) { $result = ''; $qrUrl = self::URL_ME . '&' . self::URL_VIEWERS . '&qrcode=' . $type . '&renderid=' . $id; $result = wf_modalAuto(wf_img_sized('skins/qrcode.png', __('QR code'), '16', '16'), __('QR code'), wf_img($qrUrl), ''); return ($result); } /** * Renders incoming operation view interface * * @param int $id * @return string */ public function incomingView($id) { $id = vf($id, 3); $result = ''; if (isset($this->allIncoming[$id])) { $operationData = $this->allIncoming[$id]; $employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached()); $administratorName = (isset($employeeLogins[$operationData['admin']])) ? $employeeLogins[$operationData['admin']] : $operationData['admin']; $cells = wf_TableCell(__('ID') . ' ' . $this->qrControl('in', $id), '30%', 'row2'); $cells .= wf_TableCell($id); $rows = wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Date'), '30%', 'row2'); $cells .= wf_TableCell($operationData['date']); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Contractor'), '30%', 'row2'); //storage movement if ($operationData['contractorid'] == 0) { $contractorName = $operationData['notes']; } else { $contractorName = @$this->allContractors[$operationData['contractorid']]; } $itemTypeLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $operationData['itemtypeid'], @$this->allItemTypeNames[$operationData['itemtypeid']]); $cells .= wf_TableCell($contractorName); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Category'), '30%', 'row2'); $cells .= wf_TableCell(@$this->allCategories[$this->allItemTypes[$operationData['itemtypeid']]['categoryid']]); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Warehouse item type'), '30%', 'row2'); $cells .= wf_TableCell($itemTypeLink); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Count'), '30%', 'row2'); $cells .= wf_TableCell($operationData['count'] . ' ' . $this->unitTypes[$this->allItemTypes[$operationData['itemtypeid']]['unit']]); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Price per unit'), '30%', 'row2'); $cells .= wf_TableCell($operationData['price']); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Sum'), '30%', 'row2'); $cells .= wf_TableCell(($operationData['price'] * $operationData['count'])); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Warehouse storage'), '30%', 'row2'); $cells .= wf_TableCell($this->allStorages[$operationData['storageid']]); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Barcode'), '30%', 'row2'); $cells .= wf_TableCell($operationData['barcode']); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Worker'), '30%', 'row2'); $cells .= wf_TableCell($administratorName); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Notes'), '30%', 'row2'); $cells .= wf_TableCell($operationData['notes']); $rows .= wf_TableRow($cells, 'row3'); $result .= wf_TableBody($rows, '100%', 0, 'wh_viewer'); //optional income editing controls if (cfr('WAREHOUSEINEDT')) { if ($this->altCfg['WAREHOUSE_INEDT_ENABLED']) { if ($this->isIncomeEditable($id)) { //editing form $editForm = $this->incomingEditForm($id); $result .= wf_modalAuto(web_edit_icon() . ' ' . __('Edit'), __('Edit'), $editForm, 'ubButton'); //deletion form $inDelUrl = self::URL_ME . '&' . self::URL_VIEWERS . '&showinid=' . $id . '&' . self::ROUTE_DELIN . '=' . $id; $inDelCancelUrl = self::URL_ME . '&' . self::URL_VIEWERS . '&showinid=' . $id; $inDelLabel = $this->messages->getDeleteAlert(); $result .= wf_ConfirmDialog($inDelUrl, web_delete_icon() . ' ' . __('Delete'), $inDelLabel, 'ubButton', $inDelCancelUrl, __('Delete') . '?'); } else { $result .= $this->messages->getStyledMessage(__('This operation cannot be edited or deleted'), 'warning'); $result .= wf_delimiter(); } $result .= wf_delimiter(0); } } if ($this->altCfg['PHOTOSTORAGE_ENABLED']) { $photoStorage = new PhotoStorage(self::PHOTOSTORAGE_SCOPE, $operationData['itemtypeid']); $result .= $photoStorage->renderImagesRaw(); } } else { $result = $this->messages->getStyledMessage(__('Strange exeption') . ' NO_EXISTING_INCOME_ID', 'error'); } //File storage if (@$this->altCfg['FILESTORAGE_ENABLED']) { $fileStorage = new FileStorage('WAREHOUSEINCOME', $id); $result .= wf_tag('h3') . __('Uploaded files') . wf_tag('h3', true); $result .= $fileStorage->renderFilesPreview(true, '', 'ubButton', 64, '&callback=whin'); } //ADcomments support if ($this->altCfg['ADCOMMENTS_ENABLED']) { $adcomments = new ADcomments('WAREHOUSEINCOME'); $result .= wf_tag('h3') . __('Additional comments') . wf_tag('h3', true); $result .= $adcomments->renderComments($id); } return ($result); } /** * Renders incoming operation editing form * * @param int $id * * @return string */ protected function incomingEditForm($id) { $result = ''; if (isset($this->allIncoming[$id])) { $inData = $this->allIncoming[$id]; $inputs = '<!--ugly hack to prevent datepicker autoopen -->'; $inputs .= wf_tag('input', false, '', 'type="text" name="shittyhack" style="width: 0; height: 0; top: -100px; position: absolute;"'); $inputs .= wf_DatePickerPreset('newindate', $inData['date']); $inputs .= wf_tag('br'); $inputs .= wf_HiddenInput('editincomeid', $id); $inputs .= wf_Selector('edincontractorid', $this->allContractors, __('Contractor'), $inData['contractorid'], false); $inputs .= wf_tag('br'); $inputs .= wf_Selector('edinstorageid', $this->allStorages, __('Warehouse storage'), $inData['storageid'], false); $inputs .= wf_tag('br'); $inputs .= wf_TextInput('edincount', __('Count'), $inData['count'], false, 5, 'float'); $inputs .= wf_tag('br'); $inputs .= wf_TextInput('edinprice', __('Price per unit'), $inData['price'], false, 5, 'finance'); $inputs .= wf_tag('br'); $inputs .= wf_TextInput('edinbarcode', __('Barcode'), $inData['barcode'], false, 15); $inputs .= wf_tag('br'); $inputs .= wf_TextInput('edinnotes', __('Notes'), $inData['notes'], false, 30); $inputs .= wf_tag('br'); $inputs .= wf_Submit(__('Save')); $result .= wf_Form('', 'POST', $inputs, 'glamour'); } return ($result); } /** * Catches and performs incoming operation editing request * * @return void/string */ public function incomingSaveChanges() { $result = ''; if (ubRouting::checkPost(array('editincomeid', 'newindate', 'edincontractorid', 'edinstorageid', 'edincount'))) { $id = ubRouting::post('editincomeid', 'int'); if ($this->isIncomeEditable($id)) { if ($this->altCfg['WAREHOUSE_INEDT_ENABLED']) { $inData = $this->allIncoming[$id]; $newDate = ubRouting::post('newindate'); $newContractor = ubRouting::post('edincontractorid', 'int'); $newStorage = ubRouting::post('edinstorageid', 'int'); $newCount = ubRouting::post('edincount', 'mres'); $newCount = str_replace(',', '.', $newCount); $newCount = str_replace('-', '', $newCount); $newPrice = ubRouting::post('edinprice', 'mres'); $newPrice = str_replace(',', '.', $newPrice); $newPrice = str_replace('-', '', $newPrice); $newBarcode = ubRouting::post('edinbarcode', 'mres'); $newNotes = ubRouting::post('edinnotes', 'mres'); if (zb_checkDate($newDate)) { $incomeDb = new NyanORM('wh_in'); $incomeDb->data('date', $newDate); $incomeDb->data('contractorid', $newContractor); $incomeDb->data('storageid', $newStorage); $incomeDb->data('count', $newCount); $incomeDb->data('price', $newPrice); $incomeDb->data('barcode', $newBarcode); $incomeDb->data('notes', $newNotes); $incomeDb->where('id', '=', $id); $incomeDb->save(); log_register('WAREHOUSE INCOME EDIT [' . $id . '] ITEM [' . $inData['itemtypeid'] . '] COUNT `' . $inData['count'] . '`=>`' . $newCount . '` PRICE `' . $inData['price'] . '`=>`' . $newPrice . '`'); } else { $result .= __('Wrong date format'); } } else { $result .= __('Disabled'); } } else { $result .= __('This operation cannot be edited or deleted'); } } return ($result); } /** * Deletes existing incoming operation * * @param int $id * * @return void/string */ public function incomingDelete($id) { $result = ''; $id = ubRouting::filters($id, 'int'); if ($this->isIncomeEditable($id)) { if (@$this->altCfg['WAREHOUSE_INEDT_ENABLED']) { $incomeData = $this->allOutcoming[$id]; $itemtypeId = $incomeData['itemtypeid']; $count = $incomeData['count']; $price = $incomeData['price']; $incomeDb = new NyanORM('wh_in'); $incomeDb->where('id', '=', $id); $incomeDb->delete(); log_register('WAREHOUSE INCOME DELETE [' . $id . '] ITEM [' . $itemtypeId . '] COUNT `' . $count . '` PRICE `' . $price . '`'); } else { $result .= __('Disabled'); } } else { $result .= __('This operation cannot be edited or deleted'); } return ($result); } /** * Checks is incoming operation existing and editable? * * @param int $id * * @return bool */ public function isIncomeEditable($id) { $result = true; if (isset($this->allIncoming[$id])) { $operationData = $this->allIncoming[$id]; $date = $operationData['date']; $storageId = $operationData['storageid']; $itemtypeId = $operationData['itemtypeid']; //checking outcomes if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $eachOut) { if (($eachOut['itemtypeid'] == $itemtypeId) and ($eachOut['storageid'] == $storageId)) { if ($eachOut['date'] >= $date) { //this itemtype on this storage is already touched by outcoming operations $result = false; break; } } } } } else { //not exists $result = false; } return ($result); } /** * Returns outcoming operation creation form * * @param bool $noOutControls not render storages outcoming controls * * @return string */ public function outcomingStoragesList($noOutControls = false) { $result = ''; if (!empty($this->allStorages)) { $cells = wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'row1'); foreach ($this->allStorages as $io => $each) { $storageId = $io; if ($noOutControls) { $conrolLink = $each; } else { $conrolLink = wf_Link(self::URL_ME . '&' . self::URL_OUT . '&storageid=' . $storageId, $each, false, ''); } $remainsLabel = wf_img('skins/icon_print.png', __('The remains in the warehouse storage') . ': ' . $each); $remainsPrintControls = ' ' . wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&printremainsstorage=' . $storageId, $remainsLabel); $cells = wf_TableCell($conrolLink); $cells .= wf_TableCell($remainsPrintControls); $rows .= wf_TableRow($cells, 'row5'); } $result = wf_TableBody($rows, '100%', 0, 'sortable'); } else { $result = $this->messages->getStyledMessage(__('You did not fill all the necessary directories'), 'error'); } return ($result); } /** * Returns array of items remains on some storage * * @param int $storageId * * @return array */ protected function remainsOnStorage($storageId) { $storageId = vf($storageId, 3); $result = array(); //counting income operations if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { if ($each['storageid'] == $storageId) { if (isset($result[$each['itemtypeid']])) { $result[$each['itemtypeid']] += $each['count']; } else { $result[$each['itemtypeid']] = $each['count']; } } } } //counting outcome operations if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $each) { if ($each['storageid'] == $storageId) { if (isset($result[$each['itemtypeid']])) { $result[$each['itemtypeid']] -= $each['count']; } } } } return ($result); } /** * Returns array of all itemtypes available on all storages * * @return array */ public function remainsAll() { $result = array(); if (!empty($this->allStorages)) { foreach ($this->allStorages as $storageId => $storageName) { $tmpArr = $this->remainsOnStorage($storageId); if (!empty($tmpArr)) { foreach ($tmpArr as $itemtypeId => $itemtypeCount) { if (isset($result[$itemtypeId])) { $result[$itemtypeId] += $itemtypeCount; } else { $result[$itemtypeId] = $itemtypeCount; } } } } } return ($result); } /** Туди не страшно йти Тому хто відчує І усвідомить це - Смерть перед очима, Та гірше за плечима - Там небуття сумирно жде */ /** * Returns JQuery datatables reply for storage remains itemtypes * * @param int $storageId * @return string */ public function outcomingRemainsAjaxReply($storageId) { $storageId = vf($storageId, 3); $remainItems = $this->remainsOnStorage($storageId); $json = new wf_JqDtHelper(); if (!empty($remainItems)) { foreach ($remainItems as $itemtypeid => $count) { if ($count > 0) { $actLink = ''; if (cfr('WAREHOUSEOUT')) { $actLink .= wf_Link(self::URL_ME . '&' . self::URL_OUT . '&storageid=' . $storageId . '&outitemid=' . $itemtypeid, wf_img_sized('skins/whoutcoming_icon.png', '', '10', '10') . ' ' . __('Outcoming')) . ' '; } if (cfr('WAREHOUSERESERVE')) { $actLink .= wf_Link(self::URL_ME . '&' . self::URL_RESERVE . '&storageid=' . $storageId . '&itemtypeid=' . $itemtypeid, wf_img_sized('skins/whreservation.png', '', '10', '10') . ' ' . __('Reservation')); } $reservedCount = $this->reserveGet($storageId, $itemtypeid); $data[] = @$this->allCategories[$this->allItemTypes[$itemtypeid]['categoryid']]; $data[] = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $itemtypeid, @$this->allItemTypeNames[$itemtypeid]); $itemtypeUnit = @$this->unitTypes[$this->allItemTypes[$itemtypeid]['unit']]; $data[] = ($count - $reservedCount) . ' ' . $itemtypeUnit; $data[] = $reservedCount . ' ' . $itemtypeUnit; $data[] = $count; $data[] = $actLink; $json->addRow($data); unset($data); } } } $json->getJson(); } /** * Returns items list available at storage for further outcoming operation * * @param int $storageId * @return string */ public function outcomingItemsList($storageId) { $storageId = vf($storageId, 3); $result = ''; if (!empty($this->allIncoming)) { $columns = array('Category', 'Warehouse item types', 'Count', 'Reserved', 'Total', 'Actions'); $result = wf_JqDtLoader($columns, self::URL_ME . '&' . self::URL_OUT . '&storageid=' . $storageId . '&' . self::URL_OUTAJREMAINS, true, 'Warehouse item types', 50); } else { $result = $this->messages->getStyledMessage(__('Nothing found'), 'warning'); } return ($result); } /** * Returns outcoming operations list * * @return string */ public function outcomingOperationsList() { $result = ''; if (!empty($this->allOutcoming)) { $notesFlag = ubRouting::checkGet('withnotes') ? true : false; $urlParams = ''; $opts = '"order": [[ 0, "desc" ]]'; $columns = array('ID', 'Date', 'Destination', 'Warehouse storage', 'Category', 'Warehouse item types', 'Count', 'Price per unit', 'Sum', 'Actions'); if ($notesFlag) { $columns = array('ID', 'Date', 'Destination', 'Warehouse storage', 'Category', 'Warehouse item types', 'Count', 'Price per unit', 'Sum', 'Notes', 'Actions'); $urlParams = '&withnotes=true'; } $result = wf_JqDtLoader($columns, self::URL_ME . '&' . self::URL_OUT . '&' . self::URL_OUTAJLIST . $urlParams, false, 'Outcoming operations', 50, $opts); } else { $result = $this->messages->getStyledMessage(__('Nothing found'), 'warning'); } return ($result); } /** * Returns outcoming operation destination link * * @param string $desttype * @param string $destparam * * @return string */ protected function outDestControl($desttype, $destparam) { $result = ''; switch ($desttype) { case 'task': $result = ' : ' . wf_Link('?module=taskman&edittask=' . $destparam, $destparam); break; case 'contractor': $result = ' : ' . $this->allContractors[$destparam]; break; case 'employee': $result = ' : ' . wf_Link('?module=employee', @$this->allEmployee[$destparam]); break; case 'storage': $result = ' : ' . $this->allStorages[$destparam]; break; case 'user': $result = ' : ' . wf_Link('?module=userprofile&username=' . $destparam, $destparam); break; case 'sale': $result = ''; break; case 'cancellation': $result = ''; break; case 'mistake': $result = ''; break; } $result = str_replace('"', '', $result); $result = trim($result); return ($result); } /** * Returns JQuery datatables reply for incoming operations list * * @param int $storageId * @return string */ public function outcomingListAjaxReply() { $json = new wf_JqDtHelper(); $notesFlag = ubRouting::checkGet('withnotes') ? true : false; if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $each) { $actLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $each['id'], wf_img_sized('skins/whoutcoming_icon.png', '', '10', '10') . ' ' . __('Show')); $data[] = $each['id']; $data[] = $each['date']; $data[] = $this->outDests[$each['desttype']] . $this->outDestControl($each['desttype'], $each['destparam']); $data[] = @$this->allStorages[$each['storageid']]; $data[] = @$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]; $data[] = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $each['itemtypeid'], $this->allItemTypeNames[$each['itemtypeid']]); $data[] = $each['count'] . ' ' . @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]; $data[] = $each['price']; $data[] = ($each['price'] * $each['count']); if ($notesFlag) { $data[] = $each['notes']; } $data[] = $actLink; $json->addRow($data); unset($data); } } $json->getJson(); } /** * Returns ajax selector reply for outcoming operation creation form * * @param string $destMark * @return string */ public function outcomindAjaxDestSelector($destMark) { $result = ''; $destMark = vf($destMark); $result .= wf_HiddenInput('newoutdesttype', $destMark); switch ($destMark) { case 'task': $tasksTmp = array(); $allJobTypes = ts_GetAllJobtypes(); $allUndoneTasks = ts_GetUndoneTasksArray(); $taskOutDateFlag = (@$this->altCfg['WAREHOUSE_TASKOUTDATE']) ? true : false; $taskOutEmpFlag = (@$this->altCfg['WAREHOUSE_TASKOUTEMPLOYEE']) ? true : false; if (!empty($allUndoneTasks)) { foreach ($allUndoneTasks as $io => $each) { $taskJobType = (isset($allJobTypes[$each['jobtype']])) ? $allJobTypes[$each['jobtype']] : __('Something went wrong') . ': EX_NO_JOBTYPEID'; $jobLabel = $each['address'] . ' - ' . $taskJobType; if ($taskOutDateFlag) { $jobLabel .= ', ' . $each['startdate']; } if ($taskOutEmpFlag) { $jobLabel .= ', ' . $this->allEmployee[$each['employee']]; } $tasksTmp[$io] = $jobLabel; } } $taskIdPreset = (ubRouting::checkGet('taskidpreset')) ? ubRouting::get('taskidpreset', 'int') : ''; if (!empty($taskIdPreset)) { if (!isset($tasksTmp[$taskIdPreset])) { $taskPresetFailLabel = __('Fail') . ': ' . __('Task') . ' [' . $taskIdPreset . '] ' . __('Not found'); $result .= $this->messages->getStyledMessage($taskPresetFailLabel, 'warning') . wf_delimiter(0); } } $result .= wf_Selector('newoutdestparam', $tasksTmp, __('Undone tasks'), $taskIdPreset, false); break; case 'contractor': $result .= wf_Selector('newoutdestparam', $this->allContractors, __('Contractor'), '', false); break; case 'employee': $result .= wf_Selector('newoutdestparam', $this->activeEmployee, __('Worker'), '', false); break; case 'storage': $result .= wf_Selector('newoutdestparam', $this->allStorages, __('Warehouse storage'), '', false); break; case 'user': $allUsers = zb_UserGetAllIPs(); if (!empty($allUsers)) { $allUsers = array_flip($allUsers); } $result .= wf_AutocompleteTextInput('newoutdestparam', $allUsers, __('Login'), '', false); break; case 'sale': $result .= wf_HiddenInput('newoutdestparam', 'true'); break; case 'cancellation': $result .= wf_HiddenInput('newoutdestparam', 'true'); break; case 'mistake': $result .= wf_HiddenInput('newoutdestparam', 'true'); break; default: $result = __('Strange exeption'); break; } return ($result); } /** * Returns outcoming operation creation form * * @param int $storageid * @param int $itemtypeid * @param int $reserveid * * @return string */ public function outcomingCreateForm($storageid, $itemtypeid, $reserveid = '') { $result = ''; $storageid = vf($storageid, 3); $itemtypeid = vf($itemtypeid, 3); $reserveid = vf($reserveid, 3); $tmpDests = array(); if ((isset($this->allStorages[$storageid])) and (isset($this->allItemTypes[$itemtypeid]))) { $itemData = $this->allItemTypes[$itemtypeid]; $itemUnit = $this->unitTypes[$itemData['unit']]; $storageRemains = $this->remainsOnStorage($storageid); $allRemains = $this->remainsAll(); if (isset($storageRemains[$itemtypeid])) { $itemRemainsStorage = $storageRemains[$itemtypeid]; } else { $itemRemainsStorage = 0; } if (isset($allRemains[$itemtypeid])) { $itemRemainsTotal = $allRemains[$itemtypeid]; } else { $itemRemainsTotal = 0; } if (!empty($reserveid)) { $reserveData = $this->reserveGetData($reserveid); $fromReserve = true; } else { $fromReserve = false; } $isReserved = $this->reserveGet($storageid, $itemtypeid); foreach ($this->outDests as $destMark => $destName) { $tmpDests[self::URL_ME . '&' . self::URL_OUT . '&' . self::URL_AJODSELECTOR . $destMark] = $destName; } //displayed maximum items count $maxItemCount = ($fromReserve) ? @$reserveData['count'] : ($itemRemainsStorage - $isReserved); //fix deleted reserve issue if (empty($maxItemCount)) { $maxItemCount = 0; } //form construct $inputs = wf_AjaxLoader(); $inputs .= wf_HiddenInput('newoutdate', curdate()); $inputs .= wf_AjaxSelectorAC('ajoutdestselcontainer', $tmpDests, __('Destination'), '', false); $inputs .= wf_AjaxContainer('ajoutdestselcontainer', '', $this->outcomindAjaxDestSelector('task')); $inputs .= wf_HiddenInput('newoutitemtypeid', $itemtypeid); $inputs .= wf_HiddenInput('newoutstorageid', $storageid); $inputs .= wf_TextInput('newoutcount', $itemUnit . ' (' . __('maximum') . ' ' . $maxItemCount . ')', '', true, '4', 'finance'); $midPriceLabel = ($this->recPriceFlag) ? __('recommended') : __('middle price'); $inputs .= wf_TextInput('newoutprice', __('Price') . ' (' . $midPriceLabel . ': ' . $this->getIncomeMiddlePrice($itemtypeid) . ')', '', true, '4', 'finance'); if ($fromReserve) { $inputs .= wf_HiddenInput('newoutfromreserve', $reserveid); $notesPreset = ' ' . __('from reserved on') . ' ' . @$this->allEmployee[$reserveData['employeeid']]; } else { $notesPreset = ''; } $inputs .= wf_TextInput('newoutnotes', __('Notes'), $notesPreset, true, 45); $inputs .= wf_tag('br'); $inputs .= wf_Submit(__('Create')); $form = wf_Form('', 'POST', $inputs, 'glamour'); //notifications if ($itemRemainsTotal < $itemData['reserve']) { $remainsAlert = __('The balance of goods and materials in stock is less than the amount') . ' ' . $itemData['reserve'] . ' ' . $itemUnit; } else { $remainsAlert = ''; } $remainsNotification = __('At storage') . ' ' . @$this->allStorages[$storageid] . ' ' . __('remains') . ' ' . $itemRemainsStorage . ' ' . $itemUnit . ' ' . $itemData['name']; $notifications = $this->messages->getStyledMessage($remainsNotification, 'success'); if ($isReserved) { $notifications .= $this->messages->getStyledMessage(__('Reserved') . ' ' . $isReserved . ' ' . $itemUnit, 'info'); } if ($remainsAlert) { $notifications .= $this->messages->getStyledMessage($remainsAlert, 'warning'); } $notifications .= wf_CleanDiv(); if (cfr('WAREHOUSERESERVE')) { $reserveLink = self::URL_ME . '&' . self::URL_RESERVE . '&itemtypeid=' . $itemtypeid . '&storageid=' . $storageid; $notifications .= wf_tag('div', false, '', 'style="margin: 20px 3% 0 3%;"') . wf_Link($reserveLink, wf_img('skins/whreservation.png') . ' ' . __('Reservation'), false, 'ubButton') . wf_tag('div', true); $notifications .= wf_CleanDiv(); } $cells = wf_TableCell($form, '40%'); $cells .= wf_TableCell($notifications, '', '', 'valign="top"'); $rows = wf_TableRow($cells); $result = wf_TableBody($rows, '100%', 0, ''); $result .= wf_FormDisabler(); //photostorage integration if ($this->altCfg['PHOTOSTORAGE_ENABLED']) { $photostorage = new PhotoStorage(self::PHOTOSTORAGE_SCOPE, $itemtypeid); $result .= $photostorage->renderImagesRaw(); } } else { $result = $this->messages->getStyledMessage(__('Strange exeption'), 'error'); } return ($result); } /** * Renders outcoming operation view interface * * @param int $id * @return string */ public function outcomingView($id) { $id = vf($id, 3); $result = ''; if (isset($this->allOutcoming[$id])) { $operationData = $this->allOutcoming[$id]; $employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached()); $administratorName = (isset($employeeLogins[$operationData['admin']])) ? $employeeLogins[$operationData['admin']] : $operationData['admin']; $itemTypeLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $operationData['itemtypeid'], @$this->allItemTypeNames[$operationData['itemtypeid']]); $cells = wf_TableCell(__('ID') . ' ' . $this->qrControl('out', $id), '30%', 'row2'); $cells .= wf_TableCell($id); $rows = wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Date'), '30%', 'row2'); $cells .= wf_TableCell($operationData['date']); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Destination'), '30%', 'row2'); $cells .= wf_TableCell($this->outDests[$operationData['desttype']] . $this->outDestControl($operationData['desttype'], $operationData['destparam'])); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Category'), '30%', 'row2'); $cells .= wf_TableCell(@$this->allCategories[$this->allItemTypes[$operationData['itemtypeid']]['categoryid']]); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Warehouse item type'), '30%', 'row2'); $cells .= wf_TableCell($itemTypeLink); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Count'), '30%', 'row2'); $cells .= wf_TableCell($operationData['count'] . ' ' . $this->unitTypes[$this->allItemTypes[$operationData['itemtypeid']]['unit']]); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Price per unit'), '30%', 'row2'); $cells .= wf_TableCell($operationData['price']); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Sum'), '30%', 'row2'); $cells .= wf_TableCell(($operationData['price'] * $operationData['count'])); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Warehouse storage'), '30%', 'row2'); $cells .= wf_TableCell($this->allStorages[$operationData['storageid']]); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Worker'), '30%', 'row2'); $cells .= wf_TableCell($administratorName); $rows .= wf_TableRow($cells, 'row3'); $cells = wf_TableCell(__('Notes'), '30%', 'row2'); $cells .= wf_TableCell($operationData['notes']); $rows .= wf_TableRow($cells, 'row3'); $result .= wf_TableBody($rows, '100%', 0, 'wh_viewer'); //returns controls here if (@$this->altCfg['WAREHOUSE_RETURNS_ENABLED']) { $this->loadReturns(); $outReturnData = (isset($this->allReturns[$id])) ? $this->allReturns[$id] : array(); if (empty($outReturnData)) { //specific rights check if (cfr('WAREHOUSERETURNS')) { //return controller here if (ubRouting::checkPost(array(self::PROUTE_RETURNOUTID, self::PROUTE_RETURNSTORAGE))) { $this->createReturnOperation(); ubRouting::nav(self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $id); } $returnDialogLabel = __('Return items to warehouse storage'); $result .= wf_modalAuto(wf_img('skins/return.png') . ' ' . $returnDialogLabel, $returnDialogLabel, $this->renderReturnForm($id), 'ubButton'); } } else { $returnAdmName = (isset($employeeLogins[$outReturnData['admin']])) ? $employeeLogins[$outReturnData['admin']] : $outReturnData['admin']; $returnedLabel = $outReturnData['date'] . ' ' . __('All items from this outcoming operation is already returned to warehouse storage') . ' '; $returnedLabel .= $this->allStorages[$outReturnData['storageid']] . ', '; $returnedLabel .= __('by administrator') . ' ' . $returnAdmName; $result .= $this->messages->getStyledMessage($returnedLabel, 'warning'); } } //outcome deletion controls here if (@$this->altCfg['WAREHOUSE_OUTDEL_ENABLED']) { if (cfr('ROOT')) { $outDelUrl = self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $id . '&' . self::ROUTE_DELOUT . '=' . $id; $outDelCancelUrl = self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $id; $outDelLabel = $this->messages->getDeleteAlert(); $result .= wf_ConfirmDialog($outDelUrl, web_delete_icon() . ' ' . __('Delete'), $outDelLabel, 'ubButton', $outDelCancelUrl, __('Delete') . '?'); } } $result .= wf_delimiter(0); //photostorage renderer if ($this->altCfg['PHOTOSTORAGE_ENABLED']) { $photoStorage = new PhotoStorage(self::PHOTOSTORAGE_SCOPE, $operationData['itemtypeid']); $result .= $photoStorage->renderImagesRaw(); } } else { $result = $this->messages->getStyledMessage(__('Strange exeption') . ' NO_EXISTING_OUTCOME_ID', 'error'); } //ADcomments support if ($this->altCfg['ADCOMMENTS_ENABLED']) { $adcomments = new ADcomments('WAREHOUSEOUTCOME'); $result .= wf_tag('h3') . __('Additional comments') . wf_tag('h3', true); $result .= $adcomments->renderComments($id); } return ($result); } /** * Deletes existing outcoming operation * * @param int $outId * * @return void */ public function outcomingDelete($outId) { $outId = ubRouting::filters($outId, 'int'); if (isset($this->allOutcoming[$outId])) { if (cfr('ROOT')) { if (@$this->altCfg['WAREHOUSE_OUTDEL_ENABLED']) { $outcomeData = $this->allOutcoming[$outId]; $itemtypeId = $outcomeData['itemtypeid']; $count = $outcomeData['count']; $price = $outcomeData['price']; $outcomesDb = new NyanORM('wh_out'); $outcomesDb->where('id', '=', $outId); $outcomesDb->delete(); log_register('WAREHOUSE OUTCOME DELETE [' . $outId . '] ITEM [' . $itemtypeId . '] COUNT `' . $count . '` PRICE `' . $price . '`'); } } } } /** * Renders return operation form * * @param int $outId * * @return string */ protected function renderReturnForm($outId) { $outId = ubRouting::filters($outId, 'int'); $result = ''; if (isset($this->allOutcoming[$outId])) { $outcomeData = $this->allOutcoming[$outId]; $inputs = wf_HiddenInput(self::PROUTE_RETURNOUTID, $outId); $inputs .= wf_Selector(self::PROUTE_RETURNSTORAGE, $this->allStorages, __('Warehouse storage'), $outcomeData['storageid'], true); $inputs .= wf_TextInput(self::PROUTE_RETURNPRICE, __('Price'), $outcomeData['price'], true, 5, 'finance'); $defaultNote = __('Return of an outcoming operation') . ' ID:' . $outId; $inputs .= wf_TextInput(self::PROUTE_RETURNNOTE, __('Notes'), $defaultNote, true, 30); $inputs .= wf_Submit(__('Return items to warehouse storage')); $result .= wf_Form('', 'POST', $inputs, 'glamour'); } else { $result .= $this->messages->getStyledMessage(__('Something went wrong') . ': ' . __('Outcoming operation') . ' [' . $outId . '] ' . __('Not exists'), 'error'); } return ($result); } /** * Creates new outcome return operation * * @return void */ protected function createReturnOperation() { if (ubRouting::checkPost(array(self::PROUTE_RETURNOUTID, self::PROUTE_RETURNSTORAGE))) { $outId = ubRouting::post(self::PROUTE_RETURNOUTID, 'int'); if (isset($this->allOutcoming[$outId])) { $outcomeData = $this->allOutcoming[$outId]; $curDate = curdate(); $curDateTime = curdatetime(); $whoami = whoami(); $itemtypeId = $outcomeData['itemtypeid']; $count = $outcomeData['count']; $storageId = ubRouting::post(self::PROUTE_RETURNSTORAGE, 'int'); $price = ubRouting::post(self::PROUTE_RETURNPRICE); $notes = ubRouting::post(self::PROUTE_RETURNNOTE); $barcode = ''; $contractorId = 0; //push database record about this return $this->returnsDb->data('outid', $outId); $this->returnsDb->data('storageid', $storageId); $this->returnsDb->data('itemtypeid', $itemtypeId); $this->returnsDb->data('count', $count); $this->returnsDb->data('price', $price); $this->returnsDb->data('date', $curDateTime); $this->returnsDb->data('admin', $whoami); $this->returnsDb->data('note', $notes); $this->returnsDb->create(); //cast some incoming operation on this return $this->incomingCreate($curDate, $itemtypeId, $contractorId, $storageId, $count, $price, $barcode, $notes); log_register('WAREHOUSE RETURN CREATE [' . $outId . '] ITEM [' . $itemtypeId . '] COUNT `' . $count . '` PRICE `' . $price . '`'); } } } /** * Creates new outcoming operation record in database * * @param string $date * @param string $desttype * @param string $destparam * @param int $storageid * @param int $itemtypeid * @param float $count * @param float $price * @param string $notes * @param int $reserveid * * @return string not emplty if something went wrong */ public function outcomingCreate($date, $desttype, $destparam, $storageid, $itemtypeid, $count, $price = '', $notes = '', $reserveid = '') { $result = ''; $date = mysql_real_escape_string($date); $desttype = mysql_real_escape_string($desttype); $destparam = mysql_real_escape_string($destparam); $storageid = vf($storageid, 3); $itemtypeid = vf($itemtypeid, 3); $reserveid = vf($reserveid, 3); $countF = mysql_real_escape_string($count); $countF = str_replace('-', '', $countF); $countF = str_replace(',', '.', $countF); $priceF = mysql_real_escape_string($price); $priceF = str_replace(',', '.', $priceF); if (is_numeric($priceF)) { $priceF = round($priceF, 2); } else { $priceF = 0; } $notes = mysql_real_escape_string($notes); $admin = mysql_real_escape_string(whoami()); $fromReserve = (!empty($reserveid)) ? true : false; if ($fromReserve) { $reserveData = $this->reserveGetData($reserveid); } if (isset($this->allStorages[$storageid])) { if (isset($this->allItemTypes[$itemtypeid])) { $allItemRemains = $this->remainsOnStorage($storageid); @$itemRemains = $allItemRemains[$itemtypeid]; $itemsReserved = $this->reserveGet($storageid, $itemtypeid); if ($fromReserve) { if (!empty($reserveData)) { $realRemains = $reserveData['count']; } else { //reserve deleted? $realRemains = 0; } } else { $realRemains = $itemRemains - $itemsReserved; } if ($countF <= $realRemains) { //removing items from reserve if ($fromReserve) { $this->reserveDrain($reserveid, $count); } //creating new outcome $query = "INSERT INTO `wh_out` (`id`,`date`,`desttype`,`destparam`,`storageid`,`itemtypeid`,`count`,`price`,`notes`,`admin`) VALUES " . "(NULL,'" . $date . "','" . $desttype . "','" . $destparam . "','" . $storageid . "','" . $itemtypeid . "','" . $countF . "','" . $priceF . "','" . $notes . "','" . $admin . "')"; nr_query($query); $newId = simple_get_lastid('wh_out'); log_register('WAREHOUSE OUTCOME CREATE [' . $newId . '] ITEM [' . $itemtypeid . '] COUNT `' . $count . '` PRICE `' . $price . '`'); //movement of items between different storages if ($desttype == 'storage') { $this->incomingCreate($date, $itemtypeid, 0, $destparam, $count, $price, '', __('from') . ' ' . __('Warehouse storage') . ' `' . $this->allStorages[$storageid] . '`'); } } else { if ($fromReserve) { $quantityFailNotice = __('The balance of goods and materials in stock is less than the reserved'); $quantityFailReason = ' (' . $countF . ' > ' . $realRemains . ')'; } else { $quantityFailNotice = __('The balance of goods and materials in stock is less than the amount'); $quantityFailReason = ' (' . $countF . ' > ' . $itemRemains . '-' . $itemsReserved . ')'; } $result = $this->messages->getStyledMessage($quantityFailNotice . $quantityFailReason, 'error'); } } else { $result = $this->messages->getStyledMessage(__('Strange exeption') . ' EX_WRONG_ITEMTYPE_ID', 'error'); } } else { $result = $this->messages->getStyledMessage(__('Strange exeption') . ' EX_WRONG_STORAGE_ID', 'error'); } return ($result); } /** * Returns income operations list available at storages * * @return string */ public function reportAllStoragesRemains() { $result = ''; if (!empty($this->allIncoming)) { $columns = array('Category', 'Warehouse item types', 'At storage', 'Reserved', 'Total', 'Actions'); $options=' "dom": \'<"F"lfB>rti<"F"ps>\', buttons: [\'csv\', \'excel\', \'pdf\', \'print\']'; $result = wf_JqDtLoader($columns, self::URL_ME . '&' . self::URL_REPORTS . '&' . self::URL_REAJTREM, true, 'Warehouse item types', 50, $options); } else { $result = $this->messages->getStyledMessage(__('Nothing found'), 'warning'); } return ($result); } /** * Returns JQuery datatables reply for total remains report * * @return string */ public function reportAllStoragesRemainsAjaxReply() { $all = $this->remainsAllWithReserves(); $json = new wf_JqDtHelper(); if (!empty($all)) { foreach ($all as $itemtypeId => $remains) { $itemUnits = $this->unitTypes[$this->allItemTypes[$itemtypeId]['unit']]; $realRemains = $remains['count'] - $remains['reserved']; if (($remains['count'] > 0) or ($remains['reserved'] > 0) or $realRemains > 0) { $actLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showremains=' . $itemtypeId, wf_img_sized('skins/icon_search_small.gif', '', '10', '10') . ' ' . __('Show')); $data[] = $this->allCategories[$this->allItemTypes[$itemtypeId]['categoryid']]; $data[] = wf_link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $itemtypeId, $this->allItemTypeNames[$itemtypeId]); $data[] = $realRemains . ' ' . $itemUnits; $data[] = $remains['reserved'] . ' ' . $itemUnits; $data[] = $remains['count']; $data[] = $actLink; $json->addRow($data); unset($data); } } } $json->getJson(); } /** * Returns array of all itemtypes available on all storages with their reserved counts * * @return array */ public function remainsAllWithReserves() { $result = array(); if (!empty($this->allStorages)) { foreach ($this->allStorages as $storageId => $storageName) { $tmpArr = $this->remainsOnStorage($storageId); if (!empty($tmpArr)) { /** * When you do wrong, no one forgives * When you do good, no one will care */ foreach ($tmpArr as $itemtypeId => $itemtypeCount) { $reserved = $this->reserveGet($storageId, $itemtypeId); if (isset($result[$itemtypeId])) { $result[$itemtypeId]['count'] += $itemtypeCount; $result[$itemtypeId]['reserved'] += $reserved; } else { $result[$itemtypeId]['count'] = $itemtypeCount; $result[$itemtypeId]['reserved'] = $reserved; } } } } } return ($result); } /** * Renders itemtype storage availability view * * @param int $itemtypeId * @return string */ public function reportAllStoragesRemainsView($itemtypeId) { $itemtypeId = vf($itemtypeId, 3); $result = ''; $tmpArr = array(); if (isset($this->allItemTypes[$itemtypeId])) { $itemtypeData = $this->allItemTypes[$itemtypeId]; $itemtypeUnit = $this->unitTypes[$itemtypeData['unit']]; $itemtypeName = $this->allItemTypeNames[$itemtypeId]; $cells = wf_TableCell(__('Warehouse item types')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'row1'); if (!empty($this->allStorages)) { foreach ($this->allStorages as $storageId => $StorageName) { $tmpArr = $this->remainsOnStorage($storageId); if (!empty($tmpArr)) { foreach ($tmpArr as $io => $count) { if ($io == $itemtypeId) { if ($count > 0) { $actLinks = ''; if (cfr('WAREHOUSEOUT')) { $actLinks .= wf_Link(self::URL_ME . '&' . self::URL_OUT . '&storageid=' . $storageId . '&outitemid=' . $itemtypeId, wf_img_sized('skins/whoutcoming_icon.png', '', '10', '10') . ' ' . __('Outcoming')) . ' '; } if (cfr('WAREHOUSERESERVE')) { $actLinks .= wf_Link(self::URL_ME . '&' . self::URL_RESERVE . '&storageid=' . $storageId . '&itemtypeid=' . $itemtypeId, wf_img_sized('skins/whreservation.png', '', '10', '10') . ' ' . __('Reservation')); } $cells = wf_TableCell($itemtypeName); $cells .= wf_TableCell($StorageName); $cells .= wf_TableCell($count . ' ' . $itemtypeUnit); $cells .= wf_TableCell($actLinks); $rows .= wf_TableRow($cells, 'row3'); } } } } } } $result .= wf_TableBody($rows, '100%', 0, 'sortable'); if ($this->altCfg['PHOTOSTORAGE_ENABLED']) { $photoStorage = new PhotoStorage(self::PHOTOSTORAGE_SCOPE, $itemtypeId); $result .= $photoStorage->renderImagesRaw(); } } else { $result = $this->messages->getStyledMessage(__('Something went wrong') . ' EX_WRONG_ITEMTYPE_ID', 'error'); } return ($result); } /** * Returns low reserve alert * * @return string */ protected function reserveAlert() { $result = ''; if ((!empty($this->allItemTypes)) and (!empty($this->allStorages)) and (!empty($this->allIncoming))) { $allRemains = $this->remainsAll(); foreach ($this->allItemTypes as $itemtypeId => $itemData) { $itemReserve = $itemData['reserve']; $itemName = $this->allItemTypeNames[$itemtypeId]; $itemUnit = $this->unitTypes[$itemData['unit']]; if ($itemReserve > 0) { if ((!isset($allRemains[$itemtypeId])) or ($allRemains[$itemtypeId] < $itemReserve)) { $result .= $this->messages->getStyledMessage(__('In warehouses remains less than') . ' ' . $itemReserve . ' ' . $itemUnit . ' ' . $itemName, 'warning'); } } } } return ($result); } /** * Returns low reserve alert * * @return string */ protected function reserveShoppingAlert() { $result = ''; $photoStorageEnabled = ($this->altCfg['PHOTOSTORAGE_ENABLED']) ? true : false; if ($photoStorageEnabled) { $photoStorage = new PhotoStorage(self::PHOTOSTORAGE_SCOPE, 'nope'); } if ((!empty($this->allItemTypes)) and (!empty($this->allStorages)) and (!empty($this->allIncoming))) { $allRemains = $this->remainsAll(); foreach ($this->allItemTypes as $itemtypeId => $itemData) { $itemReserve = $itemData['reserve']; $itemName = $this->allItemTypeNames[$itemtypeId]; $itemUnit = $this->unitTypes[$itemData['unit']]; if ($itemReserve > 0) { if ((!isset($allRemains[$itemtypeId])) or ($allRemains[$itemtypeId] < $itemReserve)) { $itemImage = 'skins/shopping.png'; if ($photoStorageEnabled) { $itemImagesList = $photoStorage->getImagesList($itemtypeId); if (!empty($itemImagesList)) { $itemImage = $itemImagesList[0]; //just 1st image for item } } $itemLabel = __('In warehouses remains less than') . ' ' . $itemReserve . ' ' . $itemUnit . ' ' . $itemName; $itemImagePreview = wf_img_sized($itemImage, $itemLabel, '200', '200'); $result .= wf_tag('div', false, 'dashtask', 'style="height:230px; width:230px;"'); $result .= $itemImagePreview; $result .= wf_delimiter(0); $result .= $itemName . ' < ' . ' ' . $itemReserve . ' ' . $itemUnit; $result .= wf_tag('div', true); } } } $result .= wf_CleanDiv(); } return ($result); } /** * Shows warehouse summary report * * @return void */ public function summaryReport() { $result = ''; if ($_SERVER['QUERY_STRING'] == 'module=warehouse&warehousestats=true') { $curMonth = curmonth(); $result .= $this->reserveAlert(); if (empty($this->allCategories)) { $result .= $this->messages->getStyledMessage(__('No existing categories'), 'warning'); } else { $result .= $this->messages->getStyledMessage(__('Available categories') . ': ' . sizeof($this->allCategories), 'info'); } if (empty($this->allItemTypes)) { $result .= $this->messages->getStyledMessage(__('No existing warehouse item types'), 'warning'); } else { $result .= $this->messages->getStyledMessage(__('Available item types') . ': ' . sizeof($this->allItemTypes), 'info'); } if (empty($this->allStorages)) { $result .= $this->messages->getStyledMessage(__('No existing warehouse storages'), 'warning'); } else { $result .= $this->messages->getStyledMessage(__('Available warehouse storages') . ': ' . sizeof($this->allStorages), 'info'); } if (empty($this->allContractors)) { $result .= $this->messages->getStyledMessage(__('No existing contractors'), 'warning'); } else { $result .= $this->messages->getStyledMessage(__('Available contractors') . ': ' . sizeof($this->allContractors), 'info'); } if (empty($this->allIncoming)) { $result .= $this->messages->getStyledMessage(__('No incoming operations yet'), 'warning'); } else { $result .= $this->messages->getStyledMessage(__('Total incoming operations') . ': ' . sizeof($this->allIncoming), 'success'); $monthInCount = 0; $monthInSumm = 0; foreach ($this->allIncoming as $io => $each) { if (ispos($each['date'], $curMonth)) { $monthInCount++; $monthInSumm += $each['price'] * $each['count']; } } $monthTotalsLabel = __('Current month') . ': ' . $monthInCount . ' ' . __('Incoming operations') . ' ' . __('on') . ' ' . zb_CashBigValueFormat($monthInSumm) . ' ' . __('money'); $result .= $this->messages->getStyledMessage($monthTotalsLabel, 'success'); } if (empty($this->allOutcoming)) { $result .= $this->messages->getStyledMessage(__('No outcoming operations yet'), 'warning'); } else { $result .= $this->messages->getStyledMessage(__('Total outcoming operations') . ': ' . sizeof($this->allOutcoming), 'success'); } if (!empty($result)) { $winControl = wf_Link(self::URL_ME, wf_img('skins/shopping_cart_small.png', __('Necessary purchases'))); show_window(__('Stats') . ' ' . $winControl, $result); zb_BillingStats(true); } } else { if ($_SERVER['QUERY_STRING'] == 'module=warehouse') { //shopping grid $result .= $this->reserveShoppingAlert(); if (empty($result)) { $result .= $this->messages->getStyledMessage(__('It looks like your warehouse is fine'), 'success'); } $winControl = wf_Link(self::URL_ME . '&warehousestats=true', web_icon_charts()); show_window(__('Necessary purchases') . ' ' . $winControl, $result); zb_BillingStats(true); } } } /** * Renders QR code label of some type * * @param string $type * @param int $id */ public function qrCodeDraw($type, $id) { $type = vf($type); $id = vf($id, 3); $qr = new BarcodeQR(); switch ($type) { case 'in': if (isset($this->allIncoming[$id])) { $itemName = $this->allItemTypeNames[$this->allIncoming[$id]['itemtypeid']]; $qr->text($itemName . ' ' . __('Incoming operation') . '# ' . $id); } else { $qr->text('Wrong ID'); } break; case 'out': if (isset($this->allOutcoming[$id])) { $itemName = $this->allItemTypeNames[$this->allOutcoming[$id]['itemtypeid']]; $qr->text($itemName . ' ' . __('Outcoming operation') . '# ' . $id); } else { $qr->text('Wrong ID'); } break; case 'itemtype': if (isset($this->allItemTypeNames[$id])) { $qr->text($this->allItemTypeNames[$id]); } else { $qr->text('Wrong ID'); } break; default: $qr->text('Wrong type'); break; } $qr->draw(); } /** * Renders available operations in calendar widget * * @return string */ public function reportCalendarOps() { $calendarData = ''; if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { $timestamp = strtotime($each['date']); $date = date("Y, n-1, j", $timestamp); $itemName = @$this->allItemTypeNames[$each['itemtypeid']]; $itemName = str_replace("'", '`', $itemName); $itemCount = @$each['count']; $itemUnit = @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]; $calendarData .= " { title: '" . $itemName . " - " . $itemCount . ' ' . $itemUnit . "', url: '" . self::URL_ME . '&' . self::URL_VIEWERS . '&showinid=' . $each['id'] . "', start: new Date(" . $date . "), end: new Date(" . $date . "), }, "; } } if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $each) { $timestamp = strtotime($each['date']); $date = date("Y, n-1, j", $timestamp); $itemName = @$this->allItemTypeNames[$each['itemtypeid']]; $itemCount = @$each['count']; $itemUnit = @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]; $calendarData .= " { title: '" . $itemName . " - " . $itemCount . ' ' . $itemUnit . "', url: '" . self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $each['id'] . "', start: new Date(" . $date . "), end: new Date(" . $date . "), className : 'undone', }, "; } } $result = wf_FullCalendar($calendarData); return ($result); } /** * Returns additionally spent materials list for some task * * @param int $taskid * * @return string */ public function taskMaterialsReport($taskid) { $taskid = vf($taskid, 3); $result = ''; $tmpArr = array(); $sum = 0; $outcomesCount = 0; $notesFlag = (@$this->altCfg['WAREHOUSE_TASKMANNOTES']) ? true : false; $returnsFlag = (@$this->altCfg['WAREHOUSE_RETURNS_ENABLED']) ? true : false; if ($returnsFlag) { $this->loadReturns(); } if (!empty($this->allOutcoming)) { $tmpArr = $this->allOutcoming; if (!empty($tmpArr)) { $cells = wf_TableCell(__('Date')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item type')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Price')); $cells .= wf_TableCell(__('Sum')); if ($notesFlag) { $cells .= wf_TableCell(__('Notes')); } if (cfr('WAREHOUSEOUT')) { $cells .= wf_TableCell(__('Actions')); } $rows = wf_TableRow($cells, 'row1'); foreach ($tmpArr as $io => $each) { $operationReturned = false; if ($returnsFlag) { if (isset($this->allReturns[$each['id']])) { $operationReturned = true; } } @$itemUnit = $this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]; $rowClass = 'row5'; if ($operationReturned) { $rowClass = 'ukvbankstadup'; $itemUnit .= ' ' . wf_img_sized('skins/return.png', __('All items from this outcoming operation is already returned to warehouse storage'), '12'); } $cells = wf_TableCell($each['date']); $cells .= wf_TableCell(@$this->allStorages[$each['storageid']]); $cells .= wf_TableCell(@$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]); $cells .= wf_TableCell(@$this->allItemTypeNames[$each['itemtypeid']]); $cells .= wf_TableCell($each['count'] . ' ' . $itemUnit); $cells .= wf_TableCell($each['price']); $cells .= wf_TableCell($each['price'] * $each['count']); if (cfr('WAREHOUSEOUT')) { $actLinks = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $each['id'], wf_img_sized('skins/whoutcoming_icon.png', '', '12') . ' ' . __('Show')); } else { $actLinks = ''; } if ($notesFlag) { $cells .= wf_TableCell($each['notes']); } if (cfr('WAREHOUSEOUT')) { $cells .= wf_TableCell($actLinks); } $rows .= wf_TableRow($cells, $rowClass); $sum = $sum + ($each['price'] * $each['count']); $outcomesCount++; } $cells = wf_TableCell(__('Total') . ': ' . $outcomesCount); $cells .= wf_TableCell(''); $cells .= wf_TableCell(''); $cells .= wf_TableCell(''); $cells .= wf_TableCell(''); $cells .= wf_TableCell(''); $cells .= wf_TableCell($sum); if ($notesFlag) { $cells .= wf_TableCell(''); } if (cfr('WAREHOUSEOUT')) { $cells .= wf_TableCell(''); } $rows .= wf_TableRow($cells, 'row2'); $result = wf_TableBody($rows, '100%', 0, ''); } else { $result = $this->messages->getStyledMessage(__('Nothing found'), 'info'); } } return ($result); } /** * Renders materials list spent on some tasks from array * * @param array $tasksArr * @param string $userLogin * * @return string */ public function userSpentMaterialsReport($tasksArr = array(), $userLogin = '') { $result = ''; $tmpArr = array(); $sum = 0; $outcomesCount = 0; $notesFlag = (@$this->altCfg['WAREHOUSE_TASKMANNOTES']) ? true : false; $onlyTaskFilterFlag = (ubRouting::checkGet('onlytasks')) ? true : false; $onlyUserFilterFlag = (ubRouting::checkGet('onlyuser')) ? true : false; $returnsFlag = (@$this->altCfg['WAREHOUSE_RETURNS_ENABLED']) ? true : false; if ($returnsFlag) { $this->loadReturns(); } if (!empty($this->allOutcoming)) { //prefiltering outcome operations foreach ($this->allOutcoming as $io => $each) { if (!$onlyUserFilterFlag) { //filter by taskId if ($each['desttype'] == 'task' and isset($tasksArr[$each['destparam']])) { $tmpArr[] = $each; } } if (!$onlyTaskFilterFlag) { //filter by direct user outcome operation if ($userLogin) { if ($each['desttype'] == 'user' and $each['destparam'] == $userLogin) { $tmpArr[] = $each; } } } } //rendering result if (!empty($tmpArr)) { $cells = wf_TableCell(__('Date')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item type')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Price')); $cells .= wf_TableCell(__('Sum')); if ($notesFlag) { $cells .= wf_TableCell(__('Notes')); } if (cfr('WAREHOUSEOUT')) { $cells .= wf_TableCell(__('Actions')); } $rows = wf_TableRow($cells, 'row1'); foreach ($tmpArr as $io => $each) { $operationReturned = false; if ($returnsFlag) { if (isset($this->allReturns[$each['id']])) { $operationReturned = true; } } @$itemUnit = $this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]; $rowClass = 'row5'; if ($operationReturned) { $rowClass = 'ukvbankstadup'; $itemUnit .= ' ' . wf_img_sized('skins/return.png', __('All items from this outcoming operation is already returned to warehouse storage'), '12'); } $cells = wf_TableCell($each['date']); $cells .= wf_TableCell(@$this->allStorages[$each['storageid']]); $cells .= wf_TableCell(@$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]); $cells .= wf_TableCell(@$this->allItemTypeNames[$each['itemtypeid']]); $cells .= wf_TableCell($each['count'] . ' ' . $itemUnit); $cells .= wf_TableCell($each['price']); $cells .= wf_TableCell($each['price'] * $each['count']); if (cfr('WAREHOUSEOUT')) { $actUrl = self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $each['id']; $actLinks = wf_Link($actUrl, wf_img_sized('skins/whoutcoming_icon.png', '', '12') . ' ' . __('Show')); } else { $actLinks = ''; } if ($notesFlag) { $cells .= wf_TableCell($each['notes']); } if (cfr('WAREHOUSEOUT')) { $cells .= wf_TableCell($actLinks); } $rows .= wf_TableRow($cells, $rowClass); $sum = $sum + ($each['price'] * $each['count']); $outcomesCount++; } $cells = wf_TableCell(__('Total') . ': ' . $outcomesCount); $cells .= wf_TableCell(''); $cells .= wf_TableCell(''); $cells .= wf_TableCell(''); $cells .= wf_TableCell(''); $cells .= wf_TableCell(''); $cells .= wf_TableCell($sum); if ($notesFlag) { $cells .= wf_TableCell(''); } if (cfr('WAREHOUSEOUT')) { $cells .= wf_TableCell(''); } $rows .= wf_TableRow($cells, 'row2'); $result = wf_TableBody($rows, '100%', 0, ''); } else { $result = $this->messages->getStyledMessage(__('Nothing found'), 'info'); } //append some controls here $result .= wf_delimiter(0); $filterLabelAll = wf_img('skins/icon_ok.gif') . ' ' . __('All together'); $filterUrlAll = '?module=warehouselookup&username=' . $userLogin; $result .= wf_Link($filterUrlAll, $filterLabelAll, false, 'ubButton') . ' '; $filterLabelTasks = wf_img('skins/icon_calendar.gif') . ' ' . __('Only tasks'); $filterUrlTasks = '?module=warehouselookup&username=' . $userLogin . '&onlytasks=true'; $result .= wf_Link($filterUrlTasks, $filterLabelTasks, false, 'ubButton') . ' '; $filterLabelUser = wf_img('skins/icons/userprofile.png') . ' ' . __('Only user'); $filterUrlUser = '?module=warehouselookup&username=' . $userLogin . '&onlyuser=true'; $result .= wf_Link($filterUrlUser, $filterLabelUser, false, 'ubButton') . ' '; } return ($result); } /** * Returns additionally spent materials price for some task * * @param int $taskid * * @return array sum=>float & items=>data */ public function taskMaterialsSpentPrice($taskid) { $taskid = vf($taskid, 3); $result = array(); $sum = 0; if (!empty($this->allOutcoming)) { if (!isset($this->taskOutsCache[$taskid])) { foreach ($this->allOutcoming as $io => $each) { if (($each['desttype'] == 'task') and ($each['destparam'] == $taskid)) { $sum = $sum + ($each['price'] * $each['count']); $result['items'][] = $each; } } $this->taskOutsCache[$taskid] = $result; $this->cache->set('TASKSOUTS', $this->taskOutsCache, self::CACHE_TIMEOUT); } else { $result = $this->taskOutsCache[$taskid]; if (!empty($this->taskOutsCache[$taskid]['items'])) { foreach ($this->taskOutsCache[$taskid]['items'] as $io => $each) { $sum = $sum + ($each['price'] * $each['count']); } } } } $result['sum'] = $sum; return ($result); } /** * shows printable report content * * @param $title report title * @param $data report data to printable transform * * @return void */ public function reportPrintable($title, $data) { $style = file_get_contents(CONFIG_PATH . "ukvprintable.css"); $header = wf_tag('!DOCTYPE', false, '', 'html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"'); $header .= wf_tag('html', false, '', 'xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru"'); $header .= wf_tag('head', false); $header .= wf_tag('title') . $title . wf_tag('title', true); $header .= wf_tag('meta', false, '', 'http-equiv="Content-Type" content="text/html; charset=UTF-8" /'); $header .= wf_tag('style', false, '', 'type="text/css"'); $header .= $style; $header .= wf_tag('style', true); $header .= wf_tag('script', false, '', 'src="modules/jsc/sorttable.js" language="javascript"') . wf_tag('script', true); $header .= wf_tag('head', true); $header .= wf_tag('body', false); $footer = wf_tag('body', true); $footer .= wf_tag('html', true); $title = (!empty($title)) ? wf_tag('h2') . $title . wf_tag('h2', true) : ''; $data = $header . $title . $data . $footer; die($data); } /** * Renders storage remains printable report * * @param int $storageid * * @return void */ public function reportStorageRemainsPrintable($storageId) { $storageId = vf($storageId, 3); $result = ''; if (isset($this->allStorages[$storageId])) { $storageName = $this->allStorages[$storageId]; $allRemains = $this->remainsOnStorage($storageId); $cells = wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item types')); $cells .= wf_TableCell(__('Count') . ' ' . __('On') . ' ' . $storageName); $cells .= wf_TableCell(__('Reserved')); $cells .= wf_TableCell(__('Total')); $rows = wf_TableRow($cells, 'row1'); if (!empty($allRemains)) { foreach ($allRemains as $itemtypeId => $count) { //hide itemtypes with zero ramains if ($count > 0) { $reservedCount = $this->reserveGet($storageId, $itemtypeId); $cells = wf_TableCell(@$this->allCategories[$this->allItemTypes[$itemtypeId]['categoryid']]); $cells .= wf_TableCell(@$this->allItemTypeNames[$itemtypeId]); $itemUnit = @$this->unitTypes[$this->allItemTypes[$itemtypeId]['unit']]; $cells .= wf_TableCell(($count - $reservedCount) . ' ' . $itemUnit); $cells .= wf_TableCell($reservedCount . ' ' . $itemUnit); $cells .= wf_TableCell($count . ' ' . $itemUnit); $rows .= wf_TableRow($cells, 'row3'); } } } $result = wf_TableBody($rows, '100%', 0, 'sortable'); $this->reportPrintable(__('The remains in the warehouse storage') . ': ' . $storageName, $result); } else { show_error(__('Something went wrong') . ': EX_WRONG_STORAGE_ID'); show_window('', $this->backControl(self::URL_ME . '&' . self::URL_OUT)); } } /** * Returns date remains report header * * @param int $year selected year * @param string $monthNumber selected month with leading zero * * @return string */ protected function reportDateRemainsHeader($year, $monthNumber) { $monthArr = months_array(); $monthName = rcms_date_localise($monthArr[$monthNumber]); $result = ''; $result .= wf_tag('table', false, '', 'border="0" cellspacing="2" width="100%" class="printable"'); $result .= wf_tag('colgroup', false, '', 'span="4" width="80"'); $result .= wf_tag('colgroup', true); $result .= wf_tag('colgroup', false, '', 'width="79"'); $result .= wf_tag('colgroup', true); $result .= wf_tag('colgroup', false, '', 'span="6" width="80"'); $result .= wf_tag('colgroup', true); $result .= wf_tag('tbody', false); $result .= wf_tag('tr', false, 'row2'); $result .= wf_tag('td', false, '', 'colspan="3" rowspan="3" align="center" valign="bottom"'); $result .= __('Warehouse item types'); $result .= wf_tag('td', true); $result .= wf_tag('td', false, '', 'colspan="2" rowspan="2" align="center" valign="bottom"'); $result .= __('Remains at the beginning of the month'); $result .= wf_tag('td', true); $result .= wf_tag('td', false, '', 'colspan="4" align="center" valign="bottom"') . $monthName . ' ' . $year . wf_tag('td', true); $result .= wf_tag('td', false, '', 'colspan="2" rowspan="2" align="center" valign="bottom"'); $result .= __('Remains at end of the month'); $result .= wf_tag('td', true); $result .= wf_tag('tr', true); $result .= wf_tag('tr', false, 'row2'); $result .= wf_tag('td', false, '', 'colspan="2" align="center" valign="bottom"') . __('Incoming') . wf_tag('td', true); $result .= wf_tag('td', false, '', 'colspan="2" align="center" valign="bottom"') . __('Outcoming') . ' (' . __('Signups') . '/' . __('Other') . ')' . wf_tag('td', true); $result .= wf_tag('tr', true); $result .= wf_tag('tr', false, 'row2'); $result .= wf_TableCell(__('Count')); $result .= wf_TableCell(__('Sum')); $result .= wf_TableCell(__('Count')); $result .= wf_TableCell(__('Sum')); $result .= wf_TableCell(__('Count')); $result .= wf_TableCell(__('Sum')); $result .= wf_TableCell(__('Count')); $result .= wf_TableCell(__('Sum')); $result .= wf_tag('tr', true); $result .= wf_tag('tr', false); return ($result); } /** * Returns valid formatted table row form date remains report * * @param int $itemtypeId * @param array $data * * @return string */ protected function reportDateRemainsAddRow($itemtypeId, $data) { if ($itemtypeId != '') { $itemData = $this->allItemTypeNames[$itemtypeId] . ' (' . $this->unitTypes[$this->allItemTypes[$itemtypeId]['unit']] . ')'; } else { $itemData = ''; } $cells = wf_TableCell($itemData, '', '', 'colspan="3" align="center"'); $cells .= wf_TableCell($data[0]); $cells .= wf_TableCell($data[1]); $cells .= wf_TableCell($data[2]); $cells .= wf_TableCell($data[3]); $cells .= wf_TableCell($data[4]); $cells .= wf_TableCell($data[5]); $cells .= wf_TableCell($data[6]); $cells .= wf_TableCell($data[7]); $result = wf_TableRow($cells, 'row3'); return ($result); } /** * Returns middle price for some itemtype based of all incoming operations * * @param int $itemtypeId * * @return float */ public function getIncomeMiddlePrice($itemtypeId) { $itemsCount = 0; $totalSumm = 0; if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { if ($each['itemtypeid'] == $itemtypeId) { if ($each['price'] != 0) { if ($each['contractorid'] != 0) { //ignoring move ops $totalSumm += ($each['price'] * $each['count']); $itemsCount += $each['count']; } } } } } if ($this->recPriceFlag) { if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $each) { if ($each['itemtypeid'] == $itemtypeId) { if ($each['price'] != 0) { $totalSumm -= (abs($each['price']) * $each['count']); $itemsCount -= $each['count']; } } } } } if ($itemsCount != 0) { $result = round($totalSumm / $itemsCount, 2); } else { $result = round($totalSumm, 2); } return ($result); } /** * Returns list of all signup typed tasks as id=>id * * @return array */ protected function getAllSignupTasks() { $result = array(); $signupJobTypes = array(); $signupJobTypesTmp = $this->altCfg['TASKREPORT_SIGNUPJOBTYPES']; if (!empty($signupJobTypesTmp)) { $signupJobTypesTmp = explode(',', $signupJobTypesTmp); if (!empty($signupJobTypesTmp)) { foreach ($signupJobTypesTmp as $io => $each) { $signupJobTypes[$each] = $each; } } } $allTasks = ts_GetAllTasks(); if (!empty($allTasks)) { foreach ($allTasks as $io => $each) { if (isset($signupJobTypes[$each['jobtype']])) { $result[$each['id']] = $each['id']; } } } return ($result); } /** * Renders report with list of controls to view some storages remains * * @return string */ public function reportStoragesRemains() { $result = ''; $result .= $this->outcomingStoragesList(true); return ($result); } /** * Renders date remains report * * @return string */ public function reportDateRemains() { $result = ''; $taskReportFlag = (@$this->altCfg['TASKREPORT_ENABLED']) ? true : false; $allSignupTasks = array(); if ($taskReportFlag) { $allSignupTasks = $this->getAllSignupTasks(); } $curyear = (ubRouting::checkPost('yearsel')) ? ubRouting::post('yearsel', 'int') : date("Y"); $curmonth = (ubRouting::checkPost('monthsel')) ? ubRouting::post('monthsel', 'int') : date("m"); $hideNoMoveFlag = (ubRouting::checkPost('ignorenotmoving')) ? true : false; //report form inputs $inputs = wf_YearSelector('yearsel', __('Year')) . ' '; $inputs .= wf_MonthSelector('monthsel', __('Month'), $curmonth) . ' '; $inputs .= wf_CheckInput('ignorenotmoving', __('Hide without movement'), false, $hideNoMoveFlag); $inputs .= wf_CheckInput('printmode', __('Print'), false, false); $inputs .= wf_Submit(__('Show')); $searchForm = wf_Form('', 'POST', $inputs, 'glamour'); $searchForm .= wf_CleanDiv(); //append form to result if (!wf_CheckPost(array('printmode'))) { $result .= $searchForm; } $lowerOffset = strtotime($curyear . '-' . $curmonth . '-01'); $upperOffset = strtotime($curyear . '-' . $curmonth . '-01'); $upperOffset = date("t", $upperOffset); $upperOffset = strtotime($curyear . '-' . $curmonth . '-' . $upperOffset); $incomingLower = array(); $outcomingLower = array(); if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { $incomingDate = strtotime($each['date']); if ($incomingDate < $lowerOffset) { if ($each['contractorid'] != 0) { //ignoring move ops $incomingLower[$each['id']] = $each; } } } } if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $each) { $outcomingDate = strtotime($each['date']); if ($outcomingDate < $lowerOffset) { if ($each['desttype'] != 'storage') { // ignoring move ops $outcomingLower[$each['id']] = $each; } } } } $lowerIncome = array(); if (!empty($incomingLower)) { foreach ($incomingLower as $io => $each) { if (isset($lowerIncome[$each['itemtypeid']])) { $lowerIncome[$each['itemtypeid']]['count'] = $lowerIncome[$each['itemtypeid']]['count'] + $each['count']; $lowerIncome[$each['itemtypeid']]['price'] = $lowerIncome[$each['itemtypeid']]['price'] + ($each['count'] * $each['price']); } else { $lowerIncome[$each['itemtypeid']]['count'] = $each['count']; $lowerIncome[$each['itemtypeid']]['price'] = $each['count'] * $each['price']; } } } $lowerOutcome = array(); if (!empty($outcomingLower)) { foreach ($outcomingLower as $io => $each) { if ($each['price'] == 0) { $each['price'] = $this->getIncomeMiddlePrice($each['itemtypeid']); } if (isset($lowerOutcome[$each['itemtypeid']])) { $lowerOutcome[$each['itemtypeid']]['count'] = $lowerOutcome[$each['itemtypeid']]['count'] + $each['count']; $lowerOutcome[$each['itemtypeid']]['price'] = $lowerOutcome[$each['itemtypeid']]['price'] + ($each['count'] * $each['price']); } else { $lowerOutcome[$each['itemtypeid']]['count'] = $each['count']; $lowerOutcome[$each['itemtypeid']]['price'] = $each['count'] * $each['price']; } } } //first report column here $lowerRemains = array(); if (!empty($incomingLower)) { foreach ($incomingLower as $io => $each) { $outcomeCount = (isset($lowerOutcome[$each['itemtypeid']])) ? $lowerOutcome[$each['itemtypeid']]['count'] : 0; $outcomePrice = (isset($lowerOutcome[$each['itemtypeid']])) ? $lowerOutcome[$each['itemtypeid']]['price'] : 0; $lowerRemains[$each['itemtypeid']]['count'] = $lowerIncome[$each['itemtypeid']]['count'] - $outcomeCount; $lowerRemains[$each['itemtypeid']]['price'] = $lowerIncome[$each['itemtypeid']]['price'] - $outcomePrice; } } //second column $upperIncome = array(); if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { $incomeDate = strtotime($each['date']); if (($incomeDate >= $lowerOffset) and ($incomeDate) <= $upperOffset) { if ($each['contractorid'] != 0) { //ignoring move ops if (isset($upperIncome[$each['itemtypeid']])) { $upperIncome[$each['itemtypeid']]['count'] = $upperIncome[$each['itemtypeid']]['count'] + $each['count']; $upperIncome[$each['itemtypeid']]['price'] = $upperIncome[$each['itemtypeid']]['price'] + ($each['count'] * $each['price']); } else { $upperIncome[$each['itemtypeid']]['count'] = $each['count']; $upperIncome[$each['itemtypeid']]['price'] = $each['count'] * $each['price']; } } } } } //third column $upperOutcome = array(); if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $each) { $outcomeDate = strtotime($each['date']); if (($outcomeDate >= $lowerOffset) and ($outcomeDate) <= $upperOffset) { if ($each['desttype'] != 'storage') { //ignoring move ops if ($each['price'] == 0) { $each['price'] = $this->getIncomeMiddlePrice($each['itemtypeid']); } if (isset($upperOutcome[$each['itemtypeid']])) { $upperOutcome[$each['itemtypeid']]['count'] = $upperOutcome[$each['itemtypeid']]['count'] + $each['count']; $upperOutcome[$each['itemtypeid']]['price'] = $upperOutcome[$each['itemtypeid']]['price'] + ($each['count'] * $each['price']); if ($each['desttype'] == 'task' and isset($allSignupTasks[$each['destparam']])) { $upperOutcome[$each['itemtypeid']]['sigcount'] = $upperOutcome[$each['itemtypeid']]['sigcount'] + $each['count']; $upperOutcome[$each['itemtypeid']]['sigprice'] = $upperOutcome[$each['itemtypeid']]['sigprice'] + ($each['count'] * $each['price']); } } else { $upperOutcome[$each['itemtypeid']]['count'] = $each['count']; $upperOutcome[$each['itemtypeid']]['price'] = $each['count'] * $each['price']; if ($each['desttype'] == 'task' and isset($allSignupTasks[$each['destparam']])) { $upperOutcome[$each['itemtypeid']]['sigcount'] = $each['count']; $upperOutcome[$each['itemtypeid']]['sigprice'] = $each['count'] * $each['price']; } else { $upperOutcome[$each['itemtypeid']]['sigcount'] = 0; $upperOutcome[$each['itemtypeid']]['sigprice'] = 0; } } } } } } //mixing earlier non exists items into lower remains array if (!empty($upperIncome)) { foreach ($upperIncome as $io => $each) { if (!isset($lowerRemains[$io])) { $lowerRemains[$io]['count'] = 0; $lowerRemains[$io]['price'] = 0; } } } $result .= $this->reportDateRemainsHeader($curyear, $curmonth); if (!empty($lowerRemains)) { $firstColumnTotal = 0; $secondColumnTotal = 0; $thirdColumnTotal = 0; $fourthColumnTotal = 0; foreach ($lowerRemains as $io => $each) { $appendResultsFlag = true; if ($hideNoMoveFlag) { $appendResultsFlag = false; } $itemtypeId = $io; $firstColumnCount = (isset($lowerRemains[$itemtypeId])) ? $lowerRemains[$itemtypeId]['count'] : 0; $firstColumnPrice = (isset($lowerRemains[$itemtypeId])) ? $lowerRemains[$itemtypeId]['price'] : 0; $secondColumnCount = (isset($upperIncome[$itemtypeId])) ? $upperIncome[$itemtypeId]['count'] : 0; $secondColumnPrice = (isset($upperIncome[$itemtypeId])) ? $upperIncome[$itemtypeId]['price'] : 0; $thirdColumnCount = (isset($upperOutcome[$itemtypeId])) ? $upperOutcome[$itemtypeId]['count'] : 0; $thirdColumnPrice = (isset($upperOutcome[$itemtypeId])) ? $upperOutcome[$itemtypeId]['price'] : 0; if (isset($upperOutcome[$itemtypeId]['sigcount']) and isset($upperOutcome[$itemtypeId]['sigprice'])) { $thirdColumnCountSig = (isset($upperOutcome[$itemtypeId])) ? $upperOutcome[$itemtypeId]['sigcount'] : 0; $thirdColumnPriceSig = (isset($upperOutcome[$itemtypeId])) ? $upperOutcome[$itemtypeId]['sigprice'] : 0; } else { $thirdColumnCountSig = 0; $thirdColumnPriceSig = 0; } $fourthColumnCount = $lowerRemains[$itemtypeId]['count'] + $secondColumnCount - $thirdColumnCount; $fourthColumnPrice = $lowerRemains[$itemtypeId]['price'] + $secondColumnPrice - $thirdColumnPrice; //some movements is there? if ($hideNoMoveFlag) { if ($secondColumnCount or $thirdColumnCount) { $appendResultsFlag = true; } } //appending row to results if ($appendResultsFlag) { $result .= $this->reportDateRemainsAddRow($itemtypeId, array( $firstColumnCount, round($firstColumnPrice, 2), $secondColumnCount, round($secondColumnPrice, 2), $thirdColumnCount . ' (' . $thirdColumnCountSig . '/' . ($thirdColumnCount - $thirdColumnCountSig) . ')', round($thirdColumnPrice, 2) . ' (' . $thirdColumnPriceSig . '/' . ($thirdColumnPrice - $thirdColumnPriceSig) . ')', $fourthColumnCount, round($fourthColumnPrice, 2) )); $firstColumnTotal += $firstColumnPrice; $secondColumnTotal += $secondColumnPrice; $thirdColumnTotal += $thirdColumnPrice; $fourthColumnTotal += $fourthColumnPrice; } } //table summary append $result .= $this->reportDateRemainsAddRow('', array('', $firstColumnTotal, '', $secondColumnTotal, '', $thirdColumnTotal, '', $fourthColumnTotal)); } $result .= wf_tag('tbody', true); $result .= wf_tag('table', true); if (wf_CheckPost(array('printmode'))) { die($this->reportPrintable(__('Date remains'), $result)); } return ($result); } /** * Renders itemtype history with income, outcome and reservation operations * * @param int $itemtypeId * * @return void */ public function renderItemHistory($itemtypeId) { $itemtypeId = vf($itemtypeId, 3); $result = ''; $tmpArr = array(); if (isset($this->allItemTypeNames[$itemtypeId])) { $itemTypeName = $this->allItemTypeNames[$itemtypeId]; $itemTypeCategory = $this->allCategories[$this->allItemTypes[$itemtypeId]['categoryid']]; if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { if ($each['itemtypeid'] == $itemtypeId) { $tmpArr[$each['date']]['in'][] = $each; } } } if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $each) { if ($each['itemtypeid'] == $itemtypeId) { $tmpArr[$each['date']]['out'][] = $each; } } } if (!empty($this->allReserveHistory)) { foreach ($this->allReserveHistory as $io => $each) { $reserveDate = strtotime($each['date']); $reserveDate = date("Y-m-d", $reserveDate); if ($each['itemtypeid'] == $itemtypeId) { $tmpArr[$reserveDate]['res'][] = $each; } } } if (!empty($tmpArr)) { krsort($tmpArr); $employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached()); $cells = wf_TableCell(__('Date')); $cells .= wf_TableCell(__('Type')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Price')); $cells .= wf_TableCell(__('Actions')); $cells .= wf_TableCell(__('Admin')); $rows = wf_TableRow($cells, 'row1'); foreach ($tmpArr as $io => $eachDate) { if (!empty($eachDate)) { foreach ($eachDate as $opType => $eachPack) { if (!empty($eachPack)) { foreach ($eachPack as $ix => $eachOp) { $administratorName = (isset($employeeLogins[$eachOp['admin']])) ? $employeeLogins[$eachOp['admin']] : $eachOp['admin']; $from = ''; $to = ''; $opTypeName = ''; $opLink = ''; $itemUnitType = @$this->unitTypes[$this->allItemTypes[$eachOp['itemtypeid']]['unit']]; //incoming ops if ($opType == 'in') { if ($eachOp['contractorid'] == 0) { $from = $eachOp['notes']; } else { $from = @$this->allContractors[$eachOp['contractorid']]; } $to = $this->allStorages[$eachOp['storageid']]; $opTypeName = __('Incoming'); $rowColor = '#009f04'; $opLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showinid=' . $eachOp['id'], wf_img_sized('skins/whincoming_icon.png', __('Show'), '10', '10')); } //outcoming ops if ($opType == 'out') { $from = $this->allStorages[$eachOp['storageid']]; $to = $this->outDests[$eachOp['desttype']] . $this->outDestControl($eachOp['desttype'], $eachOp['destparam']); $opTypeName = __('Outcoming'); $rowColor = '#b50000'; $opLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $eachOp['id'], wf_img_sized('skins/whoutcoming_icon.png', __('Show'), '10', '10')); } //reservation ops if ($opType == 'res') { $from = $this->allStorages[$eachOp['storageid']]; $to = @$this->allEmployee[$eachOp['employeeid']]; $opTypeName = __('Reservation'); if ($eachOp['type'] == 'create') { $opTypeName .= ' (' . __('Created') . ')'; } if ($eachOp['type'] == 'update') { $opTypeName .= ' (' . __('Updated') . ')'; } if ($eachOp['type'] == 'delete') { $opTypeName .= ' (' . __('Deleted') . ')'; } $rowColor = '#ff8a00'; } //itemtype price calculation if (isset($eachOp['price'])) { $opPrice = $eachOp['price'] * $eachOp['count']; } else { $opPrice = 0; } $cells = wf_TableCell(wf_tag('font', false, '', 'color="' . $rowColor . '"') . $eachOp['date'] . wf_tag('font', true)); $cells .= wf_TableCell(wf_tag('font', false, '', 'color="' . $rowColor . '"') . $opTypeName . wf_tag('font', true) . ' ' . $opLink); $cells .= wf_TableCell(@$this->allStorages[$eachOp['storageid']]); $cells .= wf_TableCell($eachOp['count'] . ' ' . $itemUnitType); $cells .= wf_TableCell($opPrice); $cells .= wf_TableCell($from . ' ' . wf_img('skins/arrow_right_green.png') . ' ' . $to); $cells .= wf_TableCell($administratorName); $rows .= wf_TableRow($cells, 'row3'); } } } } } $result = wf_TableBody($rows, '100%', 0, 'sortable'); if ($this->altCfg['PHOTOSTORAGE_ENABLED']) { $photoStorage = new PhotoStorage(self::PHOTOSTORAGE_SCOPE, $itemtypeId); $result .= $photoStorage->renderImagesRaw(); } } show_window(__('History') . ': ' . $itemTypeCategory . ', ' . $itemTypeName, $result); } else { show_error(__('Something went wrong')); } } /** * Renders some itemtype outomes history for some finance accounting purposes. Yep. I dont know what for. * * @return string */ public function renderItemtypeOutcomesHistory() { $result = ''; $tmpArr = array(); $filterYear = (ubRouting::checkPost('filtersomeyear')) ? ubRouting::post('filtersomeyear') : curyear(); $yearMask = $filterYear . '-'; $itemtypeId = (ubRouting::checkPost('showsomeitemtypeid')) ? ubRouting::post('showsomeitemtypeid', 'int') : 0; // Yeah. Come get some. $messages = new UbillingMessageHelper(); $totalPrice = 0; $totalCount = 0; $countUnit = ''; ///search form construction $inputs = wf_YearSelectorPreset('filtersomeyear', __('Year'), false, $filterYear, true) . ' '; $inputs .= wf_Selector('showsomeitemtypeid', $this->allItemTypeNames, __('Warehouse item type'), $itemtypeId, false) . ' '; $inputs .= wf_Submit(__('Show')); $result .= wf_Form('', 'POST', $inputs, 'glamour'); if ($itemtypeId and $filterYear) { if (isset($this->allItemTypeNames[$itemtypeId])) { $itemTypeName = $this->allItemTypeNames[$itemtypeId]; $itemTypeCategory = $this->allCategories[$this->allItemTypes[$itemtypeId]['categoryid']]; if (!empty($this->allOutcoming)) { foreach ($this->allOutcoming as $io => $each) { if ($each['itemtypeid'] == $itemtypeId) { if ($each['desttype'] == 'task') { if (ispos($each['date'], $yearMask)) { $tmpArr[$each['date']]['out'][] = $each; } } } } } if (!empty($tmpArr)) { krsort($tmpArr); $employeeLogins = unserialize(ts_GetAllEmployeeLoginsCached()); $allTasksAddress = ts_GetAllTasksAddress(); $cells = wf_TableCell(__('Date')); $cells .= wf_TableCell(__('Type')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Price')); $cells .= wf_TableCell(__('Actions')); $cells .= wf_TableCell(__('Address')); $cells .= wf_TableCell(__('Admin')); $rows = wf_TableRow($cells, 'row1'); foreach ($tmpArr as $io => $eachDate) { if (!empty($eachDate)) { foreach ($eachDate as $opType => $eachPack) { if (!empty($eachPack)) { foreach ($eachPack as $ix => $eachOp) { $administratorName = (isset($employeeLogins[$eachOp['admin']])) ? $employeeLogins[$eachOp['admin']] : $eachOp['admin']; $from = ''; $to = ''; $opTypeName = ''; $opLink = ''; $itemUnitType = @$this->unitTypes[$this->allItemTypes[$eachOp['itemtypeid']]['unit']]; //outcoming ops if ($opType == 'out') { $from = $this->allStorages[$eachOp['storageid']]; $to = $this->outDests[$eachOp['desttype']] . $this->outDestControl($eachOp['desttype'], $eachOp['destparam']); $opTypeName = __('Outcoming'); $rowColor = '#b50000'; $opLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $eachOp['id'], wf_img_sized('skins/whoutcoming_icon.png', __('Show'), '10', '10')); } //itemtype price calculation if (isset($eachOp['price'])) { $opPrice = $eachOp['price'] * $eachOp['count']; } else { $opPrice = 0; } $cells = wf_TableCell(wf_tag('font', false, '', 'color="' . $rowColor . '"') . $eachOp['date'] . wf_tag('font', true)); $cells .= wf_TableCell(wf_tag('font', false, '', 'color="' . $rowColor . '"') . $opTypeName . wf_tag('font', true) . ' ' . $opLink); $cells .= wf_TableCell(@$this->allStorages[$eachOp['storageid']]); $cells .= wf_TableCell($eachOp['count'] . ' ' . $itemUnitType); $cells .= wf_TableCell($opPrice); $cells .= wf_TableCell($from . ' ' . wf_img('skins/arrow_right_green.png') . ' ' . $to); $taskAddress = (isset($allTasksAddress[$eachOp['destparam']])) ? $allTasksAddress[$eachOp['destparam']] : ''; $cells .= wf_TableCell($taskAddress); $cells .= wf_TableCell($administratorName); $rows .= wf_TableRow($cells, 'row3'); $totalCount += $eachOp['count']; $totalPrice += $opPrice; $countUnit = $itemUnitType; } } } } } $result .= wf_TableBody($rows, '100%', 0, 'sortable'); $result .= __('Total') . ' ' . __('Count') . ': ' . $totalCount . ' ' . $countUnit; $result .= wf_tag('br'); $result .= __('Total') . ' ' . __('Price') . ': ' . $totalPrice; } else { $result .= $messages->getStyledMessage(__('Nothing found'), 'info'); } } else { $result .= $messages->getStyledMessage(__('Something went wrong'), 'error'); } } else { $result .= $messages->getStyledMessage(__('Nothing to show'), 'warning'); } return ($result); } /** * Renders per year purchases report * * @return string */ public function renderPurchasesReport() { $result = ''; $tmpResult = array(); $totalSumm = 0; $showYear = (ubRouting::checkPost('purchasesyear')) ? ubRouting::post('purchasesyear', 'int') . '-' : curyear() . '-'; $inputs = wf_YearSelectorPreset('purchasesyear', __('Year'), false, ubRouting::post('purchasesyear'), false) . ' '; $inputs .= wf_Submit(__('Show')); $result .= wf_Form('', 'POST', $inputs, 'glamour'); if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { if ($each['contractorid'] != 0) { if (ispos($each['date'], $showYear)) { $opMonth = strtotime($each['date']); $opMonth = date("m", $opMonth); $opPrice = $each['price'] * $each['count']; if (isset($tmpResult[$opMonth])) { $tmpResult[$opMonth]['count']++; $tmpResult[$opMonth]['price'] += $opPrice; } else { $tmpResult[$opMonth]['count'] = 1; $tmpResult[$opMonth]['price'] = $opPrice; } $totalSumm += $opPrice; } } } if (!empty($tmpResult)) { $yearTotalCount = 0; $yearTotalSumm = 0; $monthArr = months_array_localized(); $cells = wf_TableCell(''); $cells .= wf_TableCell(__('Month')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Sum')); $cells .= wf_TableCell(__('Visual'), '50%'); $rows = wf_TableRow($cells, 'row1'); foreach ($monthArr as $monthNum => $monthName) { if (isset($tmpResult[$monthNum])) { $monthCount = $tmpResult[$monthNum]['count']; $monthSumm = $tmpResult[$monthNum]['price']; $yearTotalCount += $monthCount; $yearTotalSumm += $monthSumm; } else { $monthCount = 0; $monthSumm = 0; } $cells = wf_TableCell($monthNum); $cells .= wf_TableCell($monthName); $cells .= wf_TableCell($monthCount); $cells .= wf_TableCell(zb_CashBigValueFormat($monthSumm)); $cells .= wf_TableCell(web_bar($monthSumm, $totalSumm)); $rows .= wf_TableRow($cells, 'row3'); } $cells = wf_TableCell(''); $cells .= wf_TableCell(__('Total')); $cells .= wf_TableCell($yearTotalCount); $cells .= wf_TableCell(zb_CashBigValueFormat($yearTotalSumm)); $cells .= wf_TableCell(''); $rows .= wf_TableRow($cells, 'row2'); $result .= wf_TableBody($rows, '100%', 0, ''); } else { $result .= $this->messages->getStyledMessage(__('Nothing found'), 'info'); } } else { $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning'); } return ($result); } /** * Renders incomes by contractor report * * @return string */ public function renderContractorIncomesReport() { $result = ''; $tmpResult = array(); $totalSumm = 0; if (ubRouting::checkPost('conincomesyear')) { $rawYear = ubRouting::post('conincomesyear', 'int'); if ($rawYear != '1488') { $showYear = $rawYear . '-'; } else { $showYear = '-'; } } else { $showYear = curyear() . '-'; } $showContractor = (ubRouting::checkPost('conincomesid')) ? ubRouting::post('conincomesid', 'int') : ''; $inputs = wf_YearSelectorPreset('conincomesyear', __('Year'), false, ubRouting::post('conincomesyear'), true) . ' '; $inputs .= wf_Selector('conincomesid', $this->allContractors, __('Contractor'), $showContractor, false); $inputs .= wf_Submit(__('Show')); $result .= wf_Form('', 'POST', $inputs, 'glamour'); if ($showContractor) { if (!empty($this->allIncoming)) { foreach ($this->allIncoming as $io => $each) { if ($each['contractorid'] != 0 and $each['contractorid'] == $showContractor) { if (ispos($each['date'], $showYear)) { $opPrice = $each['price'] * $each['count']; $tmpResult[$each['id']] = $each; $totalSumm += $opPrice; } } } if (!empty($tmpResult)) { rsort($tmpResult); //from newest $cells = wf_TableCell(__('ID')); $cells .= wf_TableCell(__('Date')); $cells .= wf_TableCell(__('Category')); $cells .= wf_TableCell(__('Warehouse item types')); $cells .= wf_TableCell(__('Count')); $cells .= wf_TableCell(__('Price per unit')); $cells .= wf_TableCell(__('Sum')); $cells .= wf_TableCell(__('Warehouse storage')); $cells .= wf_TableCell(__('Admin')); $cells .= wf_TableCell(__('Notes')); $cells .= wf_TableCell(__('Actions')); $rows = wf_TableRow($cells, 'row1'); foreach ($tmpResult as $io => $each) { $actLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showinid=' . $each['id'], wf_img_sized('skins/whincoming_icon.png', '', '10', '10') . ' ' . __('Show')); $cells = wf_TableCell($each['id']); $cells .= wf_TableCell($each['date']); $cells .= wf_TableCell(@$this->allCategories[$this->allItemTypes[$each['itemtypeid']]['categoryid']]); $cells .= wf_TableCell(wf_link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $each['itemtypeid'], $this->allItemTypeNames[$each['itemtypeid']])); $cells .= wf_TableCell($each['count'] . ' ' . @$this->unitTypes[$this->allItemTypes[$each['itemtypeid']]['unit']]); $cells .= wf_TableCell($each['price']); $cells .= wf_TableCell(round($each['price'] * $each['count'], 2)); $cells .= wf_TableCell(@$this->allStorages[$each['storageid']]); $cells .= wf_TableCell($each['admin']); $cells .= wf_TableCell($each['notes']); $cells .= wf_TableCell($actLink); $rows .= wf_TableRow($cells, 'row5'); } $result .= wf_TableBody($rows, '100%', 0, 'sortable'); $result .= wf_tag('b') . __('Total') . ': ' . zb_CashBigValueFormat($totalSumm) . wf_tag('b', true); } else { $result .= $this->messages->getStyledMessage(__('Nothing found'), 'info'); } } else { $result .= $this->messages->getStyledMessage(__('Nothing to show'), 'warning'); } } return ($result); } /** * Renders returns list container * * @return string */ public function renderReturnsReport() { $result = ''; $columns = array('Date', 'Outcoming operation', 'Warehouse storage', 'Category', 'Warehouse item type', 'Count', 'Price', 'Admin', 'Notes'); $opts = '"order": [[ 0, "desc" ]]'; $ajUrl = self::URL_ME . '&' . self::URL_REPORTS . '&returns=true&ajreturnslist=true'; $result .= wf_JqDtLoader($columns, $ajUrl, false, __('Outcoming operations'), 50, $opts); return ($result); } /** * Renders returned operations list * * @return void */ public function ajReturnsList() { $json = new wf_JqDtHelper(); $this->loadReturns(); if (!empty($this->allReturns)) { foreach ($this->allReturns as $io => $each) { $itemtypeId = $each['itemtypeid']; $itemtypeName = $this->allItemTypeNames[$itemtypeId]; $itemCategory = $this->allCategories[$this->allItemTypes[$itemtypeId]['categoryid']]; $itemtypeUnit = $this->allItemTypes[$itemtypeId]['unit']; $outOpLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&showoutid=' . $each['outid'], $each['outid']); $data[] = $each['date']; $data[] = $outOpLink; $data[] = $this->allStorages[$each['storageid']]; $data[] = $itemCategory; $itemHistLink = wf_Link(self::URL_ME . '&' . self::URL_VIEWERS . '&itemhistory=' . $itemtypeId, $itemtypeName); $data[] = $itemHistLink; $data[] = $each['count'] . ' ' . __($itemtypeUnit); $data[] = $each['price']; $data[] = $each['admin']; $data[] = $each['note']; $json->addRow($data); unset($data); } } $json->getJson(); } /** * Returns array of all existing item types * * @return array */ public function getAllItemTypes() { $result = array(); if (!empty($this->allItemTypes)) { $result = $this->allItemTypes; } return ($result); } /** * Returns array of all existing item type categories * * @return array */ public function getAllItemCategories() { $result = array(); if (!empty($this->allCategories)) { $result = $this->allCategories; } return ($result); } /** * Returns all available income operations * * @return array */ public function getAllIncomes() { return ($this->allIncoming); } /** * Returns all available outcome operations * * @return array */ public function getAllOutcomes() { return ($this->allOutcoming); } } |