mysqlmak.py 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502
  1. #!/usr/bin/python2
  2. # -*- coding: utf-8 -*-
  3. import pymysql
  4. import sqlite3 as lite
  5. import sys
  6. import decimal
  7. import datetime
  8. import copy
  9. import codecs
  10. import os
  11. import json
  12. from random import *
  13. from subprocess import Popen, PIPE
  14. from logcu import *
  15. from cari import *
  16. from stok import *
  17. from fatura import *
  18. from stokhareket import *
  19. from tblsthar import *
  20. from tblfatura import *
  21. from htmlrapor import *
  22. from sayidan_yaziya import cevir
  23. from copy import deepcopy
  24. import xlwt
  25. from mysql_ayar import *
  26. class mysqlmak:
  27. global baglanti
  28. baglanti=MysqlBaglanti()
  29. global cursor
  30. global conn
  31. global stoklistvt
  32. global l
  33. l=Logcu()
  34. def __init__(self):
  35. self.test='nesne olustu'
  36. self.stoklistvt=self.ayar_al('999','stoklist_db')
  37. def test(self):
  38. sql="select * from tblstsabit where stok_kodu='5555' "
  39. self.cursor.execute(sql)
  40. rows = self.cursor.fetchall()
  41. def stok(self,stkod):
  42. sql=open('./altyapi/sql/stok.sql','r').read()
  43. sql=sql.replace('@stkod',stkod)
  44. return self.stok_format(sql)
  45. def stok2(self,stkad):
  46. sql=open('./altyapi/sql/stok2.sql','r').read()
  47. sql=sql.replace('@stkad',str(stkad))
  48. return self.stok_format(sql)
  49. def stok_format(self,sql):
  50. stok=Stok()
  51. #self.cursor.execute(sql)
  52. #rows = self.cursor.fetchall()
  53. rows=self.calistir(sql)
  54. if(rows != None):
  55. for rowx in rows:
  56. rowx=list(rowx)
  57. if(len(rowx)>0):
  58. '''j=0
  59. for r in rowx:
  60. print j,r
  61. j+=1'''
  62. stok.sube_kodu=rowx[0]
  63. stok.kod=rowx[2]
  64. stok.isim=rowx[4]
  65. stok.grup_kodu=rowx[5]
  66. stok.kod_1=rowx[6]
  67. stok.kod_2=rowx[7]
  68. stok.kod_3=rowx[8]
  69. stok.kod_4=rowx[9]
  70. stok.kod_5=rowx[10]
  71. stok.barkod1=rowx[54]
  72. stok.barkod2=rowx[55]
  73. stok.barkod3=rowx[56]
  74. stok.barkod4=rowx[127]
  75. stok.barkod5=rowx[128]
  76. stok.barkod6=rowx[129]
  77. stok.satici_kodu=rowx[11]
  78. stok.olcu_br1=rowx[12]
  79. stok.olcu_br2=rowx[13]
  80. stok.birim_agirlik=round(float(rowx[35]),3)
  81. stok.payda=round(float(rowx[15]),3)
  82. stok.kdv_orani=rowx[37]
  83. stok.alis_kdv_kodu=rowx[57]
  84. if(rowx[26]):stok.satis_fiat1=round(float(rowx[26]),3)
  85. else:stok.satis_fiat1=0.0
  86. if(rowx[27]):stok.satis_fiat2=round(float(rowx[27]),3)
  87. else:stok.satis_fiat2=0.0
  88. if(rowx[28]):stok.satis_fiat3=round(float(rowx[28]),3)
  89. else:stok.satis_fiat3=0.0
  90. if(rowx[58]):stok.alis_fiat1=round(float(rowx[58]),3)
  91. else:stok.alis_fiat1=0.0
  92. if(rowx[59]):stok.alis_fiat2=round(float(rowx[59]),3)
  93. else:stok.alis_fiat2=0.0
  94. if(rowx[60]):stok.alis_fiat3=round(float(rowx[60]),3)
  95. else:stok.alis_fiat3=0.0
  96. #print "stok olustu"
  97. return stok
  98. else:
  99. return None
  100. def barkod_kontrol(self,kod,barkod):
  101. sql=open('./altyapi/sql/barkod_kontrol.sql','r').read()
  102. sql=sql.replace('@kod@',kod)
  103. sql=sql.replace('@barkod@',barkod)
  104. sonuc=self.calistir(sql)
  105. #print "bkon",kod,barkod
  106. if(sonuc):
  107. return sonuc[0][0]
  108. else:
  109. return sonuc
  110. def stoklar_al(self,kriter,aranan):
  111. sqldosya='./altyapi/sql/stok_sorgu.sql'
  112. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  113. sql=sql.replace('@kriter@',kriter)
  114. sql=sql.replace('@aranan@',aranan)
  115. sonuc=self.calistir(sql)
  116. stokodlar=[]
  117. for stok in sonuc:
  118. stokodlar.append(stok[0])
  119. return stokodlar
  120. def stoklar_ads(self):
  121. sqldosya='./altyapi/sql/stok_ads.sql'
  122. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  123. sonuc=self.calistir(sql)
  124. stokads={}
  125. for stok in sonuc:
  126. ads={stok[0]:stok[1]}
  127. stokads.update(ads)
  128. return stokads
  129. '''
  130. def stoklar_kdv(self):
  131. sqldosya='./altyapi/sql/stok_kdv.sql'
  132. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  133. sonuc=self.calistir(sql)
  134. stokkdv={}
  135. for stok in sonuc:
  136. kdv={stok[0]:stok[1]}
  137. stokkdv.update(kdv)
  138. return stokkdv
  139. '''
  140. def stoklar_pos(self,kriter,aranan):
  141. sqldosya='./altyapi/sql/stok_pos.sql'
  142. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  143. sql=sql.replace('@kriter@',kriter)
  144. sql=sql.replace('@aranan@',aranan)
  145. sonuc=self.calistir(sql)
  146. return sonuc
  147. def stok_harkont(self,stok):
  148. sql=open('./altyapi/sql/stok_harkont.sql','r').read()
  149. sql=sql.replace('@kod@',stok.kod)
  150. if self.calistir(sql) is None:
  151. return "yok"
  152. else:
  153. return "var"
  154. def stok_guncelle(self,stok,mod):
  155. if(mod=='s'):
  156. sql=open('./altyapi/sql/stok_sil.sql','r').read()
  157. if(mod=='g'):
  158. sql=open('./altyapi/sql/stok_guncelle.sql','r').read()
  159. if(mod=='y'):
  160. sql=open('./altyapi/sql/stok_ekle.sql','r').read()
  161. sql=sql.replace('@kod@',stok.kod)
  162. if(mod=='s'):
  163. return self.calis(sql)
  164. stok.satis_fiat1=stok.satis_fiat1.replace(',','.')
  165. stok.satis_fiat2=stok.satis_fiat2.replace(',','.')
  166. stok.satis_fiat3=stok.satis_fiat3.replace(',','.')
  167. stok.alis_fiat1=stok.alis_fiat1.replace(',','.')
  168. stok.alis_fiat2=stok.alis_fiat2.replace(',','.')
  169. stok.alis_fiat3=stok.alis_fiat3.replace(',','.')
  170. stok.birim_agirlik=stok.birim_agirlik.replace(',','.')
  171. sql=sql.replace('@isim@',stok.isim)
  172. sql=sql.replace('@barkod1@',stok.barkod1)
  173. sql=sql.replace('@barkod2@',stok.barkod2)
  174. sql=sql.replace('@barkod3@',stok.barkod3)
  175. sql=sql.replace('@barkod4@',stok.barkod4)
  176. sql=sql.replace('@barkod5@',stok.barkod5)
  177. sql=sql.replace('@barkod6@',stok.barkod6)
  178. sql=sql.replace('@alkdv@',str(stok.alis_kdv_kodu))
  179. sql=sql.replace('@satkdv@',str(stok.kdv_orani))
  180. sql=sql.replace('@satis_fiat3@',str(stok.satis_fiat3))
  181. sql=sql.replace('@satis_fiat2@',str(stok.satis_fiat2))
  182. sql=sql.replace('@satis_fiat1@',str(stok.satis_fiat1))
  183. sql=sql.replace('@alis_fiat1@',str(stok.alis_fiat1))
  184. sql=sql.replace('@alis_fiat2@',str(stok.alis_fiat2))
  185. sql=sql.replace('@alis_fiat3@',str(stok.alis_fiat3))
  186. sql=sql.replace('@grupkod@',str(stok.grup_kodu))
  187. sql=sql.replace('@kod_1@',str(stok.kod_1))
  188. sql=sql.replace('@kod_2@',str(stok.kod_2))
  189. sql=sql.replace('@kod_3@',str(stok.kod_3))
  190. sql=sql.replace('@kod_4@',str(stok.kod_4))
  191. sql=sql.replace('@kod_5@',str(stok.kod_5))
  192. sql=sql.replace('@olcu_br1@',stok.olcu_br1)
  193. sql=sql.replace('@olcu_br2@',stok.olcu_br2)
  194. sql=sql.replace('@payda@',str(stok.payda))
  195. sql=sql.replace('@birim_agirlik@',stok.birim_agirlik)
  196. sql=sql.replace('@satici_kodu@',stok.satici_kodu)
  197. return self.calis(sql)
  198. def stok_bakiye(self,stokod,merkez,tarih='getdate()'):
  199. sql=open('./altyapi/sql/stok_bakiye.sql','r').read()
  200. sql=sql.replace('@stokod@',stokod)
  201. sql=sql.replace('@merkez@',merkez)
  202. sql=sql.replace('@tarih@',tarih)
  203. rows=self.calistir(sql)
  204. if(rows):
  205. for r in rows:
  206. bakiye=r[0]
  207. if(bakiye!=None):
  208. return float(bakiye)
  209. else:
  210. return 0
  211. else:
  212. return 0
  213. def stok_satis(self,stokod,merkez,gerigun):
  214. sql=open('./altyapi/sql/stok_satis.sql','r').read()
  215. sql=sql.replace('@stokod@',stokod)
  216. sql=sql.replace('@merkez@',merkez)
  217. sql=sql.replace('@gerigun@',gerigun)
  218. rows=self.calistir(sql)
  219. if(rows):
  220. for r in rows:
  221. satis=r[0]
  222. if(satis!=None):
  223. return float(satis)
  224. else:
  225. return 0
  226. else:
  227. return 0
  228. def son_satis(self,stokod,merkez):
  229. sql=open('./altyapi/sql/son_satis.sql','r').read()
  230. sql=sql.replace('@stokod@',stokod)
  231. sql=sql.replace('@merkez@',merkez)
  232. rows=self.calistir(sql)
  233. if rows[0][0]:
  234. return self.tarih_turk(str(rows[0][0]))#.split()[0]
  235. else:
  236. return "yok"
  237. def son_giris(self,stokod,merkez):
  238. sql=open('./altyapi/sql/son_alis.sql','r').read()
  239. sql=sql.replace('@stokod@',stokod)
  240. sql=sql.replace('@merkez@',merkez)
  241. rows=self.calistir(sql)
  242. if rows[0][0]:
  243. return self.tarih_turk(str(rows[0][0]))#.split()[0]
  244. else:
  245. return "yok"
  246. def son_sayim(self,stokod,merkez):
  247. sql=open('./altyapi/sql/son_sayim.sql','r').read()
  248. sql=sql.replace('@stokod@',stokod)
  249. sql=sql.replace('@merkez@',merkez)
  250. rows=self.calistir(sql)
  251. if rows[0][0]:
  252. return self.tarih_turk(str(rows[0][0]))#.split()[0]
  253. else:
  254. return "yok"
  255. def stokadlar_getir(self,stkad):
  256. sql=open('./altyapi/sql/stokadlar_getir.sql','r').read()
  257. sql=sql.replace('@stkad@',stkad)
  258. rows=self.calistir(sql)
  259. stokadlar=[]
  260. if(rows):
  261. for r in rows:
  262. #r=str(r[0])
  263. stokadlar.append(r[0])
  264. return stokadlar
  265. else:
  266. return None
  267. def sthar_al(self,harkod):
  268. sqldosya='./altyapi/sql/sthar_al.sql'
  269. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  270. sql=sql.replace('@harkod@',str(harkod))
  271. rows=self.calistir(sql)
  272. stharnes=Tblsthar()
  273. stharnes=rows[0]
  274. return stharnes
  275. def sthar_sil(self,harkod):
  276. stharo=self.sthar_al(harkod)
  277. if(stharo[1][0:2]=='s_' or stharo[13]=="sth_servis"):
  278. sqldosya='./altyapi/sql/sthar_sil.sql'
  279. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  280. sql=sql.replace('@harkod@',harkod)
  281. sonuc=self.calis(sql)
  282. return sonuc
  283. return "sayim harici hareketler silinemez."
  284. def sthar_bilgi(self,stkod,iscari,gun="-1"):
  285. sqldosya='./altyapi/sql/sthar_bilgi.sql'
  286. if gun != "-1":
  287. sqldosya='./altyapi/sql/sthar_bilgi_gunlu.sql'
  288. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  289. sql=sql.replace('@iscari@',iscari)
  290. sql=sql.replace('@stkod@',stkod)
  291. if gun != "-1":
  292. sql=sql.replace('@gun@',str(gun))
  293. #salt sql data icin
  294. #sqldosyadata='./sql_cikti/sthar_bilgi_data.sql'
  295. #codecs.open(sqldosyadata,'w','iso-8859_9').write(sql)
  296. rapor=statikrapor()
  297. topsut=[5,6,9,9,9,9,9,9,9,9]
  298. rapor.sql(sql,alt=2,link='?sthkod',yukle="sth_yukle",sil="sth_sil",topsut=topsut)
  299. raporhar=rapor.getHtml()
  300. sqldosya='./altyapi/sql/sthar_altbilgi.sql'
  301. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  302. sql=sql.replace('@iscari@',iscari)
  303. sql=sql.replace('@stkod@',stkod)
  304. #salt sql data icin
  305. raporalt=statikrapor()
  306. topsutalt=[-1,-1,-1,-1,-1,-1]
  307. raporalt.sql(sql,alt=0,topsut=topsutalt)
  308. raporalt=raporalt.getHtml()
  309. return raporhar+"<br>"+raporalt
  310. '''
  311. sth=[]
  312. rows=self.calistir(sql)
  313. rowx=rows[0]
  314. for row in rowx:
  315. print ".....",row
  316. sth.append(str(row).decode('latin5'))
  317. return sth
  318. '''
  319. def sthar_altbilgi(self,stkod,iscari):
  320. sqldosya='./altyapi/sql/sthar_altbilgi.sql'
  321. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  322. sql=sql.replace('@iscari@',iscari)
  323. sql=sql.replace('@stkod@',stkod)
  324. #salt sql data icin
  325. #sqldosyadata='./altyapi/sql/sthar_bilgi_data.sql'
  326. #codecs.open(sqldosyadata,'w','iso-8859_9').write(sql)
  327. rapor=statikrapor()
  328. topsut=[0,0,0,0,0,0]
  329. rapor.sql(sql,alt=2,topsut=topsut)
  330. return rapor.getHtml()
  331. def stok_sorgu(self,kriter,aranan):
  332. sqldosya='./altyapi/sql/stok_sorgu.sql'
  333. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  334. sql=sql.replace('@kriter@',kriter)
  335. sql=sql.replace('@aranan@',aranan)
  336. #salt sql data icin
  337. #sqldosyadata='./altyapi/sql/sthar_bilgi_data.sql'
  338. #codecs.open(sqldosyadata,'w','iso-8859_9').write(sql)
  339. rapor=statikrapor()
  340. rapor.sql(sql,alt=2)
  341. return rapor.getHtml()
  342. def stok_sorgu2(self,kriter,aranan):
  343. sqldosya='./altyapi/sql/stok_sorgu.sql'
  344. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  345. sql=sql.replace('@kriter@',kriter)
  346. sql=sql.replace('@aranan@',aranan)
  347. rows=self.calistir(sql)
  348. sorg=[]
  349. for row in rows:
  350. sorg.append(row)
  351. return sorg
  352. def stok_sorgu_perfo(self,kriter,aranan,sira):
  353. sira=int(sira)
  354. if kriter=="FKOD":
  355. rows=self.sthar_detay(aranan,sonuc='dizi')
  356. stoko=1
  357. else:
  358. sqldosya='./altyapi/sql/stok_sorgu.sql'
  359. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  360. sql=sql.replace('@kriter@',kriter)
  361. sql=sql.replace('@aranan@',aranan)
  362. rows=self.calistir(sql)
  363. stoko=0
  364. if rows and sira<len(rows):
  365. if rows[sira]:
  366. return rows[sira][stoko]
  367. return 0
  368. def stkno_kontrol(self,stoklistno):
  369. con = lite.connect(self.ayar_al('999','stoklist_db'))
  370. with con:
  371. cur = con.cursor()
  372. #eskisi
  373. cur.execute("SELECT * FROM stoklist where stoklistno='"+stoklistno+"'")
  374. #cur.execute("select sira,stkod,stkad,sum(miktar),bf,tutar,stoklistno from stoklist where stoklistno='"+stoklistno+"' group by stkad,bf order by stkad")
  375. rows = cur.fetchall()
  376. return rows
  377. def stk_bilgi(self,stoklistno=""):
  378. con = lite.connect(self.ayar_al('999','stoklist_db'))
  379. #con = lite.connect('stoklist.db')
  380. with con:
  381. cur = con.cursor()
  382. #eskisi
  383. cur.execute("SELECT stkod,stkad,miktar,bf,tutar,stoklistno,sira FROM stoklist where stoklistno='"+stoklistno+"'")
  384. #cur.execute("select sira,stkod,stkad,sum(miktar),bf,tutar,stoklistno from stoklist where stoklistno='"+stoklistno+"' group by stkad,bf order by stkad")
  385. rows = cur.fetchall()
  386. col_names = [i[0] for i in cur.description]
  387. rapor=statikrapor()
  388. topsut=[9,9,9,2,9,4,9,9]
  389. rapor.sql(sqlstr=None,alt=2,sqlitero=rows,colnam=col_names,link='/stk_goster?sira',yukle="stk_yukle",sil="stk_sil",topsut=topsut,noekle=1)
  390. return rapor.getHtml()
  391. def stk_satsil(self,sirano):
  392. con = lite.connect(self.ayar_al('999','stoklist_db'))
  393. with con:
  394. cur = con.cursor()
  395. cur.execute("DELETE FROM stoklist WHERE sira="+sirano)
  396. return "tamam"
  397. def stk_list_al(self):
  398. con = lite.connect(self.ayar_al('999','stoklist_db'))
  399. with con:
  400. try:
  401. cur = con.cursor()
  402. cur.execute("SELECT stoklistno FROM stoklist group by stoklistno")
  403. rows = cur.fetchall()
  404. except:
  405. hata=sys.exc_info()[1]
  406. if(hata[1]=='database is locked'):
  407. l.yaz('stoklist.db kilitlendi.')
  408. return rows
  409. def stk_kontrol(self,stoklistno=""):
  410. con = lite.connect(self.ayar_al('999','stoklist_db'))
  411. onay="olumsuz"
  412. with con:
  413. cur = con.cursor()
  414. cur.execute("SELECT stkod FROM stoklist where stoklistno='"+stoklistno+"'")
  415. rows = cur.fetchall()
  416. for row in rows:
  417. onay="olumlu"
  418. if(self.stok(row[0]) is None):
  419. l.yaz("stk_kontrol sorunlu stok: "+row[0])
  420. onay="olumsuz"
  421. return onay
  422. def stk_al(self,stoklistno=""):
  423. con = lite.connect(self.ayar_al('999','stoklist_db'))
  424. with con:
  425. cur = con.cursor()
  426. cur.execute("SELECT * FROM stoklist where stoklistno='"+stoklistno+"'")
  427. rows = cur.fetchall()
  428. return rows
  429. def stk_rapor_al(self,stkno=""):
  430. rapordizi=[]
  431. i=0
  432. kyt=self.stk_al(stkno)
  433. uz=len(kyt)
  434. for ro in kyt:
  435. i+=1
  436. if i<=uz:
  437. rapordizi.append([i,ro[2],ro[3],ro[4],ro[5]])
  438. rapor=statikrapor()
  439. dizibas=['no','isim','miktar','bf','tutar']
  440. top_sutlar=[-1,-1,2,-1,4]
  441. rapor_html=rapor.diziYhtml(rapordizi,dizibas,top_sutlar)
  442. return rapor_html
  443. def stk_birlestir(self,stkana,stkek):
  444. con = lite.connect(self.ayar_al('999','stoklist_db'))
  445. with con:
  446. ekstklist=self.stk_al(stkek)
  447. cur = con.cursor()
  448. for sthar in ekstklist:
  449. stharek=(sthar[1],sthar[2],float(sthar[3]),float(sthar[4]),float(sthar[5]),stkana)
  450. cur.execute("INSERT INTO stoklist (stkod,stkad,miktar,bf,tutar,stoklistno) VALUES(?, ?,?, ?, ?,?)", stharek)
  451. return "tamam"
  452. return "stk birlestirme sorun"
  453. def stk_sira_al(self,stoklistno=""):
  454. con = lite.connect(self.ayar_al('999','stoklist_db'))
  455. with con:
  456. cur = con.cursor()
  457. cur.execute("SELECT sira FROM stoklist where stoklistno='"+stoklistno+"'")
  458. rows = cur.fetchall()
  459. return rows
  460. def stk_har_al(self,guncelsira=""):
  461. con = lite.connect(self.ayar_al('999','stoklist_db'))
  462. with con:
  463. cur = con.cursor()
  464. cur.execute("SELECT stkod,stkad,miktar,bf FROM stoklist where sira='"+guncelsira+"'")
  465. rows = cur.fetchall()
  466. return rows[0]
  467. def stk_kopyala(self,stkno,dbkopya=""):
  468. arrsiv=0
  469. stknokop="kopya_"+stkno
  470. if dbkopya=="":
  471. dbkopya=self.ayar_al('999','stoklist_db')
  472. con = lite.connect(dbkopya)
  473. else:
  474. arsiv=1
  475. con = lite.connect("stk_yedek/"+dbkopya+".db")
  476. with con:
  477. tbl_kont="SELECT name FROM sqlite_master WHERE type='table' AND name='stoklist';"
  478. stkhar=self.stk_al(stkno)
  479. cur = con.cursor()
  480. cur.execute(tbl_kont)
  481. rows = cur.fetchall()
  482. if len(rows)>0:
  483. print "mevcut vt'e eklendi."
  484. else:
  485. print "yeni vt olusturuldu."
  486. cur.execute("CREATE TABLE stoklist(sira INTEGER PRIMARY KEY AUTOINCREMENT,stkod TEXT,stkad TEXT,miktar REAL,bf REAL,tutar REAL,stoklistno INT)")
  487. for sthar in stkhar:
  488. stharek=(sthar[1],sthar[2],float(sthar[3]),float(sthar[4]),float(sthar[5]),stknokop)
  489. cur.execute("INSERT INTO stoklist (stkod,stkad,miktar,bf,tutar,stoklistno) VALUES(?, ?,?, ?, ?,?)", stharek)
  490. con.close()
  491. #self.stk_sil(stkno)
  492. '''
  493. if arsiv==1:
  494. komut="move "+dbkopya+" stk_yedek/"+dbkopya+".db"
  495. print komut
  496. os.system(komut)
  497. '''
  498. return "tamam"
  499. def stkgcc_tablo_olustur(self):
  500. con = lite.connect("stoklist.db")
  501. cur = con.cursor()
  502. with con:
  503. cur.execute("CREATE TABLE stoklistgcc(sira INTEGER PRIMARY KEY AUTOINCREMENT,stkod TEXT,stkad TEXT,miktar REAL,bf REAL,tutar REAL,stoklistno INT)")
  504. print "stoklistgcc tablosu olusturuldu."
  505. def stk_tablo_olustur(self):
  506. con = lite.connect("stoklist.db")
  507. cur = con.cursor()
  508. with con:
  509. cur.execute("CREATE TABLE stoklist(sira INTEGER PRIMARY KEY AUTOINCREMENT,stkod TEXT,stkad TEXT,miktar REAL,bf REAL,tutar REAL,stoklistno INT)")
  510. print "stoklist tablosu olusturuldu."
  511. def stk_fsb2_al(self,stoklistno=""):
  512. con = lite.connect(self.ayar_al('999','stoklist_db'))
  513. with con:
  514. cur = con.cursor()
  515. cur.execute("SELECT sum(tutar) FROM stoklist where stoklistno='"+stoklistno+"'")
  516. rows = cur.fetchall()
  517. toptut=rows[0][0]
  518. top=str(toptut)
  519. return round(float(top),3)
  520. def stk_ekle(self,stharyeni):
  521. con = lite.connect(self.ayar_al('999','stoklist_db'))
  522. with con:
  523. cur = con.cursor()
  524. cur.execute("INSERT INTO stoklist (stkod,stkad,miktar,bf,tutar,stoklistno) VALUES(?, ?,?, ?, ?,?)", stharyeni)
  525. def stk_iskonto(self,stkno,icra):
  526. con = lite.connect(self.ayar_al('999','stoklist_db'))
  527. with con:
  528. cur = con.cursor()
  529. cur.execute("update stoklist set bf=round(bf*"+str(icra)+",2),tutar=round(tutar*"+str(icra)+",2) where stoklistno='"+str(stkno)+"'")
  530. return "tamam"
  531. def stk_yeniad(self,stkno,yeniad):
  532. con = lite.connect(self.ayar_al('999','stoklist_db'))
  533. with con:
  534. cur = con.cursor()
  535. sql="update stoklist set stoklistno='"+yeniad+"' where stoklistno='"+str(stkno)+"'"
  536. cur.execute(sql)
  537. return "tamam"
  538. def stk_sil(self,stkno):
  539. con = lite.connect(self.ayar_al('999','stoklist_db'))
  540. with con:
  541. cur = con.cursor()
  542. cur.execute("delete from stoklist where stoklistno='"+stkno+"'")
  543. con.close()
  544. def stkdb_icaktar(self,dbsec):
  545. yuk="_"+str(randint(0,9999))
  546. con = lite.connect(self.ayar_al('999','stoklist_db'))
  547. conye = lite.connect(dbsec)
  548. with con:
  549. cur = con.cursor()
  550. with conye:
  551. curye = conye.cursor()
  552. curye.execute("SELECT * FROM stoklist")
  553. rowsye = curye.fetchall()
  554. for sthar in rowsye:
  555. if '@' in sthar[6]:
  556. ystk=sthar[6]
  557. else:
  558. ystk=sthar[6]+yuk
  559. stharek=(sthar[1],sthar[2],float(sthar[3]),float(sthar[4]),float(sthar[5]),ystk)
  560. cur.execute("INSERT INTO stoklist (stkod,stkad,miktar,bf,tutar,stoklistno) VALUES(?, ?,?, ?, ?,?)", stharek)
  561. #os.system("del stk_yedek/"+dbsec+".db")
  562. return "tamam"
  563. return "sorun olustu"
  564. def stk_fsb_al(self,stoklistno="",gc='C'):
  565. fsb=[]
  566. stharlar=self.stk_al(stoklistno)
  567. sira=0
  568. ntop=0
  569. gtop=0
  570. for sthar in stharlar:
  571. sira+=1
  572. if gc=='C':
  573. kdvsi=self.stok(sthar[1]).kdv_orani
  574. else:
  575. kdvsi=self.stok(sthar[1]).alis_kdv_kodu
  576. if kdvsi is None:
  577. print "stok kdv bulunamadi"
  578. return None
  579. fiyat=sthar[4]
  580. bf=0.0
  581. nf=0.0
  582. nf=decimal.Decimal("%.2g" % nf)
  583. bf=decimal.Decimal("%.2g" % bf)
  584. nf=decimal.Decimal("%.8g" % fiyat)
  585. bf=nf
  586. kdvdahilmi="H"
  587. nttr=nf*(decimal.Decimal("%.3g" % sthar[3]))
  588. gttr=bf*(decimal.Decimal("%.3g" % sthar[3]))*(kdvsi+100)/100
  589. ntop+=nttr.quantize(decimal.Decimal(10) ** -2)
  590. gtop+=gttr.quantize(decimal.Decimal(10) ** -2)
  591. fsb.append("toplam="+str(ntop))
  592. fsb.append("+kdv="+str(gtop))
  593. #dahilse
  594. stharlar=self.stk_al(stoklistno)
  595. sira=0
  596. ntop=0
  597. gtop=0
  598. for sthar in stharlar:
  599. sira+=1
  600. kdvsi=self.stok(sthar[1]).kdv_orani
  601. fiyat=sthar[4]
  602. bf=0.0
  603. nf=0.0
  604. nf=decimal.Decimal("%.2g" % nf)
  605. bf=decimal.Decimal("%.2g" % bf)
  606. bf=decimal.Decimal("%.8g" % fiyat)
  607. nf=(decimal.Decimal("%.8g" % fiyat)*100)/(kdvsi+100)
  608. nttr=nf*(decimal.Decimal("%.3g" % sthar[3]))
  609. gttr=bf*(decimal.Decimal("%.3g" % sthar[3]))
  610. ntop+=nttr.quantize(decimal.Decimal(10) ** -2)
  611. gtop+=gttr.quantize(decimal.Decimal(10) ** -2)
  612. fsb.append("-kdv="+str(ntop))
  613. fsb.append("toplam="+str(gtop))
  614. return fsb
  615. def stok_virmanx(self,eskikod,yenikod):
  616. cev="tamam"
  617. if(self.stok(yenikod) is None):
  618. sql=open('./altyapi/sql/stok_virman.sql','r').read()
  619. sql=sql.replace('@eskikod@',eskikod)
  620. sql=sql.replace('@yenikod@',yenikod)
  621. cev=self.calis(sql)
  622. if(cev=='tamam'):
  623. sql=open('./altyapi/sql/stok_virman2.sql','r').read()
  624. sql=sql.replace('@eskikod@',eskikod)
  625. sql=sql.replace('@yenikod@',yenikod)
  626. cev=self.calis(sql)
  627. return cev
  628. def cari(self,carikod):
  629. sql=open('./altyapi/sql/cari.sql','r').read()
  630. sql=sql.replace('@carikod',carikod)
  631. return self.cari_format(sql)
  632. def cari2(self,cariad):
  633. cari=Cari()
  634. sql=open('./altyapi/sql/cari2.sql','r').read()
  635. sql=sql.replace('@cariad',cariad)
  636. return self.cari_format(sql)
  637. def cari_format(self,sql):
  638. cari=Cari()
  639. #self.cursor.execute(sql)
  640. #rows = self.cursor.fetchall()
  641. rows=self.calistir(sql)
  642. if(rows != None):
  643. for rowx in rows:
  644. rowx=list(rowx)
  645. if(len(rowx)>0):
  646. #niteliklerin aktarilmasi
  647. cari.kod=rowx[2]
  648. cari.isim=rowx[6]
  649. cari.adres = rowx[14]
  650. cari.tel=rowx[3]
  651. cari.tel2=rowx[69]
  652. cari.vergino=rowx[17]
  653. cari.vergiyer=rowx[16]
  654. cari.sube=rowx[0]
  655. cari.muhkod=rowx[38]
  656. cari.eposta=rowx[46]
  657. cari.tip=rowx[7]
  658. cari.iskoran=rowx[32]
  659. cari.vadegunu=rowx[33]
  660. cari.cari_tip=rowx[7]
  661. cari.grupkod=rowx[8]
  662. cari.kod1=rowx[9]
  663. cari.kod2=rowx[10]
  664. cari.iban=rowx[13]
  665. return cari
  666. else:
  667. return None
  668. def cariler_getir(self, aranan,tip=""):
  669. cariler=[]
  670. sql=open('./altyapi/sql/cariler_getir.sql','r').read()
  671. sql=sql.replace('@aranan@',aranan)
  672. if tip!="":
  673. tip="and cari_tip in ('"+str(tip)+"')"
  674. sql=sql.replace('@tip@',tip)
  675. #print sql
  676. rows=self.calistir(sql)
  677. if(rows):
  678. for rowx in rows:
  679. if(len(rowx)>0):
  680. cariad=rowx[1]
  681. cariler.append(cariad+"@"+rowx[0])
  682. else:
  683. return None
  684. return cariler
  685. def carihar_dokum(self,kaynak,hedef,bastarih,sontarih,sonuc="dizi"):
  686. sqldosya='./altyapi/sql/carihar_dokum.sql'
  687. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  688. sql=sql.replace('@kaynak@',kaynak)
  689. sql=sql.replace('@iscari@',hedef)
  690. bastarih=self.tarih_format(bastarih)
  691. sontarih=self.tarih_format(sontarih)
  692. sql=sql.replace('@bastarih@',bastarih)
  693. sql=sql.replace('@sontarih@',sontarih)
  694. codecs.open("sql_cikti/cari_hareket_data.sql",'w','iso-8859_9').write(sql)
  695. if(sonuc=='html'):
  696. rapor=statikrapor()
  697. rapor.sql(sql)
  698. return rapor.getHtml()
  699. if(sonuc=='dizi'):
  700. rows=self.calistir(sql)
  701. return rows
  702. def carihar_bilgi(self,iscari,karsicari,tarih,fisno,islemturu,hartip,irsdurum,sonuc="",modul="f",chgun=-1):
  703. mcari=iscari
  704. kcari=karsicari
  705. rapor_yas=""
  706. #print iscari,karsicari,tarih,fisno,islemturu,"gc:",hartip,irsdurum
  707. sqldosya=""
  708. devir_rapor=""
  709. if modul=="c":
  710. if chgun == -1:
  711. sqldosya='./altyapi/sql/carihar_bilgi_cx.sql'
  712. elif chgun == 7:
  713. sqldosya='./altyapi/sql/carihar_bilgi_cz.sql'
  714. else:
  715. sqldosya='./altyapi/sql/carihar_bilgi_cy.sql'
  716. if modul=="f":
  717. sqldosya='./altyapi/sql/carihar_bilgi_f.sql'
  718. iscariler=iscari.split(',')
  719. iscari=""
  720. for cari in iscariler:
  721. iscari+="'"+cari+"',"
  722. iscari=iscari[1:len(iscari)-2]
  723. if islemturu in ['K','B']:
  724. sqldosya='./altyapi/sql/carihar_bilgi_kb.sql'
  725. if(karsicari!=""):
  726. karsicariler=karsicari.split(',')
  727. karsicari=""
  728. for cari in karsicariler:
  729. karsicari+="'"+cari+"',"
  730. karsicari="'"+karsicari[1:len(karsicari)-2]+"'"
  731. else:
  732. karsicari="select cari_kod from tblcasabit"
  733. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  734. if modul=="c":
  735. sql=sql.replace('@chgun@',str(chgun))
  736. sql=sql.replace('@iscari@',iscari)
  737. sql=sql.replace('@karsicari@',karsicari)
  738. if(tarih!=""):
  739. tarih=self.tarih_format(tarih)
  740. sql=sql.replace('@tarih_kriter@',"tarih='"+tarih+"' and ")
  741. else:
  742. sql=sql.replace('@tarih_kriter@',"")
  743. if(fisno!=""):
  744. sql=sql.replace('@fisno_kriter@',"fno='"+fisno+"' and")
  745. else:
  746. sql=sql.replace('@fisno_kriter@',"")
  747. if(islemturu!=""):
  748. sql=sql.replace('@islem_kriter@',"islem_turu='"+islemturu[0]+"' and")
  749. else:
  750. sql=sql.replace('@islem_kriter@',"")
  751. if(hartip!=""):
  752. sql=sql.replace('@hartip_kriter@',"ftip='"+hartip[0]+"' and")
  753. else:
  754. sql=sql.replace('@hartip_kriter@',"")
  755. if(irsdurum!=""):
  756. sql=sql.replace('@irs_kriter@',"irs='"+irsdurum+"' and")
  757. else:
  758. sql=sql.replace('@irs_kriter@',"")
  759. #14:35 09.01.2015
  760. #if islemturu=='K':
  761. if islemturu in ['K','B']:
  762. sqldosyak='./altyapi/sql/kasa_devir.sql'
  763. sqlk=codecs.open(sqldosyak,'r','iso-8859_9').read()
  764. sqlk=sqlk.replace('@kaynak@',iscari)
  765. sqlk=sqlk.replace('@tarih@',tarih)
  766. codecs.open("sql_cikti/kasa_devir_data.sql",'w','iso-8859_9').write(sqlk+"\n")
  767. rapork=statikrapor()
  768. topsutk=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]
  769. rapork.sql(sqlk,alt=1)
  770. devir_rapor=rapork.getHtml()
  771. if(sonuc=='html'):
  772. rapor=statikrapor()
  773. topsut=[5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1]
  774. #14:35 09.01.2015
  775. #if islemturu=='K':
  776. if islemturu in ['K','B']:
  777. topsut=[3,4,5,-1,-1,-1,-1,-1,-1,-1,-1]
  778. codecs.open("sql_cikti/carihar_sorgu_data.sql",'w','iso-8859_9').write(sql+"\n")
  779. rapor.sql(sql,rapbas="rapor",alt=1,link='?fkod',yukle="cahar_yukle",sil="cahar_sil",topsut=topsut)
  780. if modul=="c":
  781. rapor_yas=self.cari_yaslandirma(kcari,mcari,tarih="")
  782. return rapor.getHtml()+"<br>"+devir_rapor+"<br>"+rapor_yas
  783. if(sonuc=='dizi'):
  784. rows=self.calistir(sql)
  785. return rows
  786. def cari_sorgu(self,kriter,aranan,rtip="html"):
  787. sqldosya='./altyapi/sql/cari_sorgu.sql'
  788. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  789. sql=sql.replace('@kriter@',kriter)
  790. sql=sql.replace('@aranan@',aranan)
  791. #salt sql data icin
  792. #sqldosyadata='./altyapi/sql/sthar_bilgi_data.sql'
  793. codecs.open("sql_cikti/cari_sorgu_data.sql",'w','iso-8859_9').write(sql)
  794. if rtip=="html":
  795. rapor=statikrapor()
  796. rapor.sql(sql,alt=2)
  797. return rapor.getHtml()
  798. else:
  799. rows=self.calistir(sql)
  800. return rows
  801. def cari_guncelle(self,cari,mod):
  802. if(mod=='s'):
  803. sql=open('./altyapi/sql/cari_sil.sql','r').read()
  804. if(mod=='g'):
  805. sql=open('./altyapi/sql/cari_guncelle.sql','r').read()
  806. if(mod=='y'):
  807. sql=open('./altyapi/sql/cari_ekle.sql','r').read()
  808. sql=sql.replace('@kod@',cari.kod)
  809. if(mod=='s'):
  810. return self.calis(sql)
  811. sql=sql.replace('@isim@',cari.isim)
  812. sql=sql.replace('@adres@',cari.adres)
  813. sql=sql.replace('@tel@',cari.tel)
  814. sql=sql.replace('@tel2@',cari.tel2)
  815. sql=sql.replace('@vergino@',cari.vergino)
  816. sql=sql.replace('@vergiyer@',cari.vergiyer)
  817. sql=sql.replace('@eposta@',cari.eposta)
  818. sql=sql.replace('@cari_tip@',cari.cari_tip)
  819. sql=sql.replace('@iban@',cari.iban)
  820. sql=sql.replace('@vade_gunu@',str(cari.vade_gunu))
  821. sql=sql.replace('@grupkod@',cari.grupkod)
  822. sql=sql.replace('@kod1@',cari.kod1)
  823. return self.calis(sql)
  824. def sthar_detay(self,fkod,sonuc='dizi',tasarim=1):
  825. if(tasarim==1):
  826. sqldosya='./altyapi/sql/sthar_detay.sql'
  827. if(tasarim==2):
  828. sqldosya='./altyapi/sql/sthar_detay2.sql'
  829. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  830. sql=sql.replace('@fkod@',str(fkod))
  831. if(sonuc=='html'):
  832. rapor=statikrapor()
  833. rapor.sql(sql,alt=2)
  834. return rapor.getHtml()
  835. '''
  836. rapor=statikrapor()
  837. #topsut=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,11]
  838. rapor.sql(sql,alt=1,link='/incno?incno',yukle="stk_yukle",sil="stk_sil",topsut=[])
  839. return rapor.getHtml()
  840. '''
  841. if(sonuc=='dizi'):
  842. rows=self.calistir(sql)
  843. return rows
  844. print "sorgu sonuc tipi secilmedi"
  845. return None
  846. def sthar_detay_baslik(self,fkod,link="",sonuc='dizi',tasarim=1):
  847. if(tasarim==1):
  848. sqldosya='./altyapi/sql/sthar_detay_baslik.sql'
  849. if(tasarim==2):
  850. sqldosya='./altyapi/sql/sthar_detay_baslik2.sql'
  851. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  852. sql=sql.replace('@fkod@',str(fkod))
  853. if(sonuc=='html'):
  854. rapor=statikrapor()
  855. rapor.sql(sql,alt=2,link=link)
  856. return rapor.getHtml()
  857. if(sonuc=='dizi'):
  858. rows=self.calistir(sql)
  859. return rows[0]
  860. print "sorgu sonuc tipi secilmedi"
  861. return None
  862. def fatura_irsler(self,fkod,sonuc='dizi'):
  863. sqldosya='./altyapi/sql/fatura_irsler.sql'
  864. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  865. sql=sql.replace('@fkod@',str(fkod))
  866. if(sonuc=='html'):
  867. rapor=statikrapor()
  868. rapor.sql(sql,alt=2)
  869. return rapor.getHtml()
  870. if(sonuc=='dizi'):
  871. rows=self.calistir(sql)
  872. return rows
  873. print "sorgu sonuc tipi secilmedi"
  874. return None
  875. def fatura_kayitbilgi(self,fkod,sonuc='dizi'):
  876. sqldosya='./altyapi/sql/fatura_kayitbilgi.sql'
  877. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  878. sql=sql.replace('@fkod@',str(fkod))
  879. if(sonuc=='html'):
  880. rapor=statikrapor()
  881. rapor.sql(sql,alt=2)
  882. return rapor.getHtml()
  883. if(sonuc=='dizi'):
  884. rows=self.calistir(sql)
  885. return rows
  886. print "sorgu sonuc tipi secilmedi"
  887. return None
  888. def stknoYfkod(self,stkno):
  889. try:
  890. gecde=stkno.split('.stk')[0]
  891. fkod=gecde.split('fkod')[1]
  892. if(fkod):
  893. return fkod
  894. except:
  895. return None
  896. def stk_fiyatdeg(self,stkno,bftip):
  897. con = lite.connect(self.ayar_al('999','stoklist_db'))
  898. stkharlar=self.stk_al(stkno)
  899. stknopar=stkno.split('@')
  900. if len(stknopar)>1:
  901. kaynak=stknopar[0]
  902. hedef=stknopar[1]
  903. else:
  904. kaynak=""
  905. hedef=""
  906. for stkhar in stkharlar:
  907. stkod=stkhar[1]
  908. stok=self.stok(stkod)
  909. if(bftip=='3'):
  910. bf=stok.satis_fiat3
  911. if(bftip=='2'):
  912. bf=stok.satis_fiat2
  913. if(bftip=='1'):
  914. bf=stok.satis_fiat1
  915. if(bftip=='4'):
  916. bf=stok.alis_fiat1
  917. if(bftip=='5'):
  918. bf=stok.alis_fiat2
  919. if(bftip=='6'):
  920. bf=stok.alis_fiat3
  921. if(bftip=='7'):
  922. bf=self.sonalim_bf(kaynak,hedef,stok.kod)
  923. if(bftip=='8'):
  924. bf=self.sonsatis_bf(kaynak,hedef,stok.kod)
  925. with con:
  926. cur = con.cursor()
  927. cur.execute("update stoklist set bf="+str(bf)+",tutar=miktar*"+str(bf)+" where stkod='"+stkod+"' and stoklistno='"+str(stkno)+"'")
  928. return "tamam"
  929. def sth_ekle(self,kaynak,fisno,tarih,stkod,miktar,olcubr,bf):
  930. now = datetime.datetime.now()
  931. tblsthar=Tblsthar()
  932. tblsthar.stok_kodu=stkod
  933. tblsthar.fisno=fisno
  934. tblsthar.miktar=miktar
  935. tblsthar.tarih=self.tarih_format(tarih)
  936. tblsthar.bf=bf
  937. tblsthar.olcubr=olcubr
  938. tblsthar.nf=tblsthar.bf
  939. tblsthar.kaynak=kaynak
  940. tblsthar.hedef="sth_servis"
  941. tblsthar.kdvoran=self.stok(tblsthar.stok_kodu).kdv_orani
  942. tblsthar.finckeyno=0
  943. tblsthar.kayittarihi=now
  944. gc="G"
  945. if(float(tblsthar.miktar)<0):
  946. gc="C"
  947. tblsthar.miktar=-1*float(tblsthar.miktar)
  948. tblsthar.ftip=gc
  949. stharsql=""
  950. sqlsthar=open('./altyapi/sql/tblsthar_ekle.sql','r').read()
  951. stharsql=tblsthar.ekle(sqlsthar)
  952. #print stharsql
  953. self.calistir(stharsql)
  954. return "tamam"
  955. def sth_sil(self,incno):
  956. sql=""
  957. sql=open('./altyapi/sql/sthar_sil.sql','r').read()
  958. sql=sql.replace('@harkod@',str(incno))
  959. self.calistir(sql)
  960. return "tamam"
  961. def sth_bilgi(self,merkez,fisno,sonuc='dizi',tasarim=1):
  962. fkod=self.fkod_al(fisno,merkez)
  963. if(tasarim==1):
  964. sqldosya='./altyapi/sql/sthar_detay.sql'
  965. if(tasarim==2):
  966. sqldosya='./altyapi/sql/sthar_detay2.sql'
  967. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  968. sql=sql.replace('@fkod@',str(fkod))
  969. if(sonuc=='html'):
  970. rapor=statikrapor()
  971. #topsut=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,11]
  972. rapor.sql(sql,alt=1,link='/incno?incno',yukle="sth_yukle",sil="sth_sil",topsut=[])
  973. return rapor.getHtml()
  974. if(sonuc=='dizi'):
  975. rows=self.calistir(sql)
  976. return rows
  977. print "sorgu sonuc tipi secilmedi"
  978. return None
  979. def sthlar_al(self,fkod):
  980. sql=open('./altyapi/sql/sthlar_al.sql','r').read()
  981. sql=sql.replace('@fkod@',str(fkod))
  982. rows=self.calistir(sql)
  983. if(rows):
  984. return rows
  985. else:
  986. return None
  987. def nakli_agirlik(self,stkno):
  988. urunler=self.stk_al(stkno)
  989. topagr=0.0
  990. for urun in urunler:
  991. topagr+=self.stok(urun[1]).birim_agirlik*urun[3]
  992. return topagr
  993. def fat_sth_islem(self,tblsthar,mod='e'):
  994. now = datetime.datetime.now()
  995. fatura=self.fatura_yukle(tblsthar.finckeyno)
  996. kdvdurum=fatura.kdvdurum
  997. stok=self.stok(tblsthar.stok_kodu)
  998. kdvsi=stok.kdv_orani
  999. #sthar tablosu icin kayit nesnesinin olusturulmasi
  1000. tblsthar.fisno=fatura.fno
  1001. tblsthar.tarih=fatura.tarih
  1002. tblsthar.kaynak=fatura.kaynak
  1003. tblsthar.hedef=fatura.hedef
  1004. tblsthar.kayittarihi=now
  1005. tblsthar.vadetarihi=fatura.vadetarihi
  1006. tblsthar.ftip=fatura.ftip
  1007. tblsthar.duzeltmetarihi=now
  1008. tblsthar.takipkod=fatura.takipkod
  1009. tblsthar.kdvoran=kdvsi
  1010. tblsthar.olcubr=stok.olcu_br1
  1011. tblsthar.miktar=float(tblsthar.miktar)
  1012. fiyat=tblsthar.bf
  1013. fiyat=float(fiyat)
  1014. ntop=0
  1015. gtop=0
  1016. bf=0.0
  1017. nf=0.0
  1018. nf=decimal.Decimal("%.8g" % nf)
  1019. bf=decimal.Decimal("%.8g" % bf)
  1020. if(kdvdurum=="H"):
  1021. nf=decimal.Decimal("%.8g" % fiyat)
  1022. satirkdv=decimal.Decimal("%.8g" % (nf+(nf*(kdvsi/100))))
  1023. bf=nf
  1024. kdvdahilmi="H"
  1025. nttr=nf*(decimal.Decimal("%.8g" % tblsthar.miktar))
  1026. gttr=bf*(decimal.Decimal("%.8g" % tblsthar.miktar))*(kdvsi+100)/100
  1027. else:
  1028. kdvdurum="E"
  1029. bf=decimal.Decimal("%.8g" % fiyat)
  1030. satirkdv=decimal.Decimal("%.8g" % (bf-(bf/((kdvsi/100)+1))))
  1031. nf=(decimal.Decimal("%.8g" % fiyat)*100)/(kdvsi+100)
  1032. nf=decimal.Decimal("%.8g" % nf)
  1033. nttr=nf*(decimal.Decimal("%.8g" % tblsthar.miktar))
  1034. gttr=bf*(decimal.Decimal("%.8g" % tblsthar.miktar))
  1035. satirkdv=decimal.Decimal("%.8g" % satirkdv)*decimal.Decimal("%.8g" % tblsthar.miktar)
  1036. satirkdv=decimal.Decimal("{:10.2f}".format(satirkdv))
  1037. if(kdvsi==1.00):
  1038. if mod=='e':fatura.kdv1top+=satirkdv
  1039. if mod=='s':fatura.kdv1top-=satirkdv
  1040. if(kdvsi==8.00):
  1041. if mod=='e':fatura.kdv8top+=satirkdv
  1042. if mod=='s':fatura.kdv8top-=satirkdv
  1043. if(kdvsi==18.00):
  1044. if mod=='e':fatura.kdv18top+=satirkdv
  1045. if mod=='s':fatura.kdv18top-=satirkdv
  1046. tblsthar.nf=nf
  1047. tblsthar.bf=bf
  1048. ntop=nttr.quantize(decimal.Decimal(10) ** -2)
  1049. gtop=gttr.quantize(decimal.Decimal(10) ** -2)
  1050. gtop=decimal.Decimal("{:10.2f}".format(gtop))
  1051. ntop=decimal.Decimal("{:10.2f}".format(ntop))
  1052. if mod=='e':fatura.khtutar+=ntop
  1053. if mod=='s':fatura.khtutar-=ntop
  1054. if mod=='e':fatura.kdtutar+=gtop
  1055. if mod=='s':fatura.kdtutar-=gtop
  1056. if mod=='e':fatura.kdvtoplam+=gtop-ntop
  1057. if mod=='s':fatura.kdvtoplam-=gtop-ntop
  1058. if mod=='e':fatura.geneltoplam+=gtop
  1059. if mod=='s':fatura.geneltoplam-=gtop
  1060. if mod=='e':sira=self.fis_sonsira(fatura.fno)+1
  1061. if mod=='s':sira=self.fis_sonsira(fatura.fno)-1
  1062. fatura.fatkalem_adedi=sira
  1063. tblsthar.sira=sira
  1064. if mod=='e':#self.sth_ekle(tblsthar.kaynak,tblsthar.fisno,tblsthar.tarih,tblsthar.stok_kodu,tblsthar.miktar,tblsthar.olcubr,tblsthar.bf)
  1065. stharsql=""
  1066. sqlsthar=open('./altyapi/sql/tblsthar_ekle.sql','r').read()
  1067. stharsql=tblsthar.ekle(sqlsthar)
  1068. self.calistir(stharsql)
  1069. if mod=='s':self.sth_sil(tblsthar.incno)
  1070. sqlfatura=codecs.open('./altyapi/sql/tblfatura_ekle.sql','r','iso-8859_9').read()
  1071. self.faturaust_sil(fatura.inckeyno)
  1072. fatura.inckeyno=tblsthar.finckeyno
  1073. faturasql=fatura.ekle(sqlfatura)
  1074. #print faturasql
  1075. self.calistir(faturasql)
  1076. return "tamam"
  1077. def chvade_duzen(self,fkod,yenivade):
  1078. sql=""
  1079. yenivade=self.tarih_format(yenivade)
  1080. sql=open('./altyapi/sql/chvade_duzen.sql','r').read()
  1081. sql=sql.replace('@fkod@',str(fkod))
  1082. sql=sql.replace('@yenivade@',str(yenivade))
  1083. self.calis(sql)
  1084. return "tamam"
  1085. def spr_fisler(self,merkez):
  1086. sql=open('./altyapi/sql/spr_fisler.sql','r').read()
  1087. sql=sql.replace('@merkez@',str(merkez))
  1088. rows=self.calistir(sql)
  1089. fisler=[]
  1090. if(rows):
  1091. return rows
  1092. else:
  1093. return None
  1094. def fis_sonsira(self,fisno):
  1095. sql=open('./altyapi/sql/fis_sonsira.sql','r').read()
  1096. sql=sql.replace('@fisno@',str(fisno))
  1097. rows=self.calistir(sql)
  1098. sira=rows[0][0]
  1099. if(sira is not None):
  1100. return sira
  1101. else:
  1102. return 0
  1103. def fatura_kdvdurum(self,fkod):
  1104. sql=open('./altyapi/sql/fatura_kdvdurum.sql','r').read()
  1105. sql=sql.replace('@fkod@',str(fkod))
  1106. rows=self.calistir(sql)
  1107. durum=rows[0][0]
  1108. if(durum is not None):
  1109. return durum
  1110. else:
  1111. return 'X'
  1112. def fkod_al(self,fisno,merkez):
  1113. sql=open('./altyapi/sql/fkod_al.sql','r').read()
  1114. sql=sql.replace('@fisno@',str(fisno))
  1115. sql=sql.replace('@merkez@',str(merkez))
  1116. rows=self.calistir(sql)
  1117. if(rows is not None):
  1118. fkod=rows[0][0]
  1119. return fkod
  1120. else:
  1121. return -1
  1122. def faturalama(self,fatura,kayitmodu):
  1123. #fatura guncelleme stkno uzerinden kontrol edilir.eski silinir,yeni degerle kayit yapilir.
  1124. islem_turu=""
  1125. eski_fkod=""
  1126. if(kayitmodu=='g'):
  1127. #guncfkod=self.stknoYfkod(fatura.stharlistno)
  1128. if(fatura.fkod):
  1129. print fatura.fkod+" nolu fatura guncellenmek uzere silindi."
  1130. eski_fkod=fatura.fkod
  1131. self.fatura_sil(fatura.fkod)
  1132. fatura.stharlist=self.stharlist_al(fatura.stharlistno)
  1133. fatura.tarih=self.tarih_format(fatura.tarih)
  1134. fatura.vadetarih=self.tarih_format(fatura.vadetarih)
  1135. sira=0
  1136. ftip=''
  1137. ntop=0
  1138. gtop=0
  1139. kdv1top=decimal.Decimal(0.0)
  1140. kdv8top=decimal.Decimal(0.0)
  1141. kdv18top=decimal.Decimal(0.0)
  1142. now = datetime.datetime.now()
  1143. stharsql=""
  1144. sqlsthar=open('./altyapi/sql/tblsthar_ekle.sql','r').read()
  1145. finckeyno=0
  1146. ftip=fatura.fattip
  1147. cari=self.cari(fatura.hedef)
  1148. #fatura vadesi guiden geldii icin simdilik iptal edildi.
  1149. #vadesi=cari.vadegunu
  1150. caritip=cari.cari_tip
  1151. fatura.caritip=caritip
  1152. if(fatura.islem =='F'):
  1153. print "kalemler ekleniyor"
  1154. ax=datetime.datetime.now()
  1155. for sthar in fatura.stharlist:
  1156. sira+=1
  1157. stok=self.stok(sthar.stkod)
  1158. if stok is None:
  1159. print "mak.faturalama() tanimsiz stok",sthar.stkod
  1160. return "olumsuz"
  1161. kdvsi=stok.alis_kdv_kodu
  1162. if ftip=='C':
  1163. kdvsi=stok.kdv_orani
  1164. #son alimyer ekleme
  1165. '''oto_alim=open('./altyapi/sql/oto_fiyat_guncelle.sql','r').read()
  1166. sql=sql.replace('@stkod@',str(sthar.stkod))
  1167. sql=sql.replace('@hedef@',str(fatura.hedef))
  1168. self.calis(sql)
  1169. '''
  1170. kdvdurum=fatura.kdvdurum
  1171. #sthar tablosu icin kayit nesnesinin olusturulmasi
  1172. tblsthar=Tblsthar()
  1173. tblsthar.stok_kodu=stok.kod
  1174. tblsthar.fisno=fatura.fisno
  1175. tblsthar.miktar=sthar.miktar
  1176. fatura.toplam_mik+=tblsthar.miktar
  1177. if (stok.isim!=sthar.stokad):
  1178. tblsthar.aciklama=sthar.stokad
  1179. tblsthar.tarih=fatura.tarih
  1180. tblsthar.duzeltmetarihi=now
  1181. tblsthar.takipkod=fatura.takipkod
  1182. tblsthar.sira=sira
  1183. tblsthar.kdvoran=kdvsi
  1184. tblsthar.vadetarihi=fatura.vadetarih
  1185. tblsthar.olcubr=stok.olcu_br1
  1186. fiyat=sthar.bf
  1187. fiyat=float(fiyat)
  1188. bf=0.0
  1189. nf=0.0
  1190. nf=decimal.Decimal("%.8g" % nf)
  1191. bf=decimal.Decimal("%.8g" % bf)
  1192. if(kdvdurum=="H"):
  1193. nf=decimal.Decimal("%.8g" % fiyat)
  1194. satirkdv=decimal.Decimal("%.8g" % ((nf*(kdvsi/100))))
  1195. bf=nf*(kdvsi+100)/100
  1196. nttr=nf*(decimal.Decimal("%.8g" % sthar.miktar))
  1197. gttr=nf*(decimal.Decimal("%.8g" % sthar.miktar))*(kdvsi+100)/100
  1198. else:
  1199. kdvdurum="E"
  1200. bf=decimal.Decimal("%.8g" % fiyat)
  1201. satirkdv=decimal.Decimal("%.8g" % (bf-(bf/((kdvsi/100)+1))))
  1202. nf=(decimal.Decimal("%.8g" % fiyat)*100)/(kdvsi+100)
  1203. nf=decimal.Decimal("%.8g" % nf)
  1204. nttr=nf*(decimal.Decimal("%.8g" % sthar.miktar))
  1205. gttr=bf*(decimal.Decimal("%.8g" % sthar.miktar))
  1206. satirkdv=decimal.Decimal("%.8g" % satirkdv)*decimal.Decimal("%.8g" % sthar.miktar)
  1207. satirkdv=decimal.Decimal("{:10.2f}".format(satirkdv))
  1208. if(kdvsi==1.00):kdv1top+=satirkdv
  1209. if(kdvsi==8.00):kdv8top+=satirkdv
  1210. if(kdvsi==18.00):kdv18top+=satirkdv
  1211. tblsthar.nf=nf
  1212. tblsthar.bf=bf
  1213. tblsthar.kaynak=fatura.kaynak
  1214. tblsthar.hedef=fatura.hedef
  1215. tblsthar.finckeyno=999999
  1216. tblsthar.kayittarihi=now
  1217. tblsthar.ftip=ftip
  1218. #bir hareket icin tblsthar vt nesnesinini sqlinin olusturulma
  1219. stharsql+=tblsthar.ekle(sqlsthar)
  1220. ntop+=nttr.quantize(decimal.Decimal(10) ** -2)
  1221. gtop+=gttr.quantize(decimal.Decimal(10) ** -2)
  1222. ay=datetime.datetime.now()
  1223. print sira,"kalem eklendi.",(ay-ax).total_seconds(),"sn"
  1224. gtop=decimal.Decimal("{:10.2f}".format(gtop))
  1225. ntop=decimal.Decimal("{:10.2f}".format(ntop))
  1226. cari1=self.cari(fatura.kaynak)
  1227. cari2=self.cari(fatura.hedef)
  1228. islem_turu=fatura.islem
  1229. if(kayitmodu=='g'):
  1230. finckeyno=eski_fkod
  1231. if(kayitmodu=='y'):
  1232. finckeyno=self.finckeyno_al()
  1233. if(kayitmodu=='sayim'):
  1234. finckeyno=-1
  1235. if(fatura.islem !='F'):
  1236. ntop=fatura.tutar
  1237. if ntop<=0:
  1238. fatura.fattip='C'
  1239. ntop=ntop*-1
  1240. else:
  1241. fatura.fattip='G'
  1242. gtop=ntop
  1243. #vadesi=0
  1244. kdvdurum="E"
  1245. sira=0
  1246. kdv1top=0
  1247. kdv8top=0
  1248. kdv18top=0
  1249. if(fatura.fisno==""):
  1250. fatura.fisno=islem_turu+fatura.fattip+str(finckeyno)
  1251. fatura.ntop=ntop
  1252. fatura.gtop=gtop
  1253. fatura.kalemsay=sira
  1254. fatura.kdv1top=kdv1top
  1255. fatura.kdv8top=kdv8top
  1256. fatura.kdv18top=kdv18top
  1257. if(kayitmodu=='sayim'):
  1258. finckeyno=0
  1259. fatura.fincno=finckeyno
  1260. fatura.islem_turu=islem_turu
  1261. stharsql=stharsql.replace("999999",str(finckeyno))
  1262. print "sql0"
  1263. self.calistir(stharsql)
  1264. print "sql1"
  1265. kayitsonuc=self.faturalama2(fatura=fatura)
  1266. return kayitsonuc
  1267. def faturalama2(self,fatura):
  1268. #sqlfatura=open('./altyapi/sql/tblfatura_ekle.sql','r').read()
  1269. sqlfatura=codecs.open('./altyapi/sql/tblfatura_ekle.sql','r','iso-8859_9').read()
  1270. vadesay=fatura.vadesay
  1271. ntop=fatura.ntop
  1272. gtop=fatura.gtop
  1273. sira=fatura.kalemsay
  1274. tblfatura=Tblfatura()
  1275. tblfatura.kaynak=fatura.kaynak
  1276. tblfatura.ftip=fatura.fattip
  1277. tblfatura.fno=fatura.fisno
  1278. tblfatura.hedef=fatura.hedef
  1279. tblfatura.tarih=fatura.tarih
  1280. tblfatura.khtutar=ntop
  1281. tblfatura.kdtutar=gtop
  1282. tblfatura.kdvtoplam=gtop-ntop
  1283. tblfatura.vadetarihi=fatura.vadetarih
  1284. tblfatura.cari_tip=fatura.caritip
  1285. tblfatura.islem_turu=fatura.islem_turu
  1286. tblfatura.med=fatura.med
  1287. tblfatura.irs=fatura.irs
  1288. tblfatura.kdvdurum=fatura.kdvdurum
  1289. tblfatura.fatkalem_adedi=sira
  1290. tblfatura.toplam_mik=fatura.toplam_mik
  1291. #toplam_mik de olacak burada
  1292. tblfatura.geneltoplam=gtop
  1293. tblfatura.kayityapankul=fatura.kaydeden
  1294. tblfatura.duzeltmeyapankul=fatura.kaydeden
  1295. tblfatura.kayittarihi=datetime.datetime.now()
  1296. tblfatura.duzeltmetarihi=datetime.datetime.now()
  1297. tblfatura.aciklama=fatura.aciklama
  1298. tblfatura.takipkod=fatura.takipkod
  1299. tblfatura.inckeyno=fatura.fincno
  1300. tblfatura.kdv1top=fatura.kdv1top
  1301. tblfatura.kdv8top=fatura.kdv8top
  1302. tblfatura.kdv18top=fatura.kdv18top
  1303. vadesay=int(vadesay)
  1304. if(vadesay<1):
  1305. vadesay=1
  1306. if(vadesay>=1):
  1307. ortvade=round(float(gtop)/int(vadesay),3)
  1308. for i in range(vadesay):
  1309. tblfatura.geneltoplam=ortvade
  1310. if(i>0):
  1311. tblfatura.inckeyno=self.finckeyno_al()
  1312. faturasql=tblfatura.ekle(sqlfatura)
  1313. self.calistir(faturasql)
  1314. return "tamam"
  1315. def ust_guncelle(self,fatura):
  1316. fatura.vadetarih=self.tarih_format(fatura.vadetarih)
  1317. fatura.tarih=self.tarih_format(fatura.tarih)
  1318. #sql=open('./altyapi/sql/ust_guncelle.sql','r').read()
  1319. sql=codecs.open('./altyapi/sql/ust_guncelle.sql','r','iso-8859_9').read()
  1320. sql=sql.replace('@fno@',str(fatura.fisno))
  1321. sql=sql.replace('@fkod@',str(fatura.fkod))
  1322. sql=sql.replace('@tarih@',str(fatura.tarih))
  1323. sql=sql.replace('@vadetarih@',str(fatura.vadetarih))
  1324. sql=sql.replace('@tutar@',str(fatura.tutar))
  1325. sql=sql.replace('@aciklama@',fatura.aciklama)
  1326. sql=sql.replace('@med@',str(fatura.med))
  1327. sql=sql.replace('@irs@',str(fatura.irs))
  1328. sql=sql.replace('@hedef@',str(fatura.hedef))
  1329. sonuc=self.calis(sql)
  1330. vade_kont=self.vadeleme_kontrol(fatura.fkod)
  1331. if vade_kont!=0.0:
  1332. return "tutar uyusmazligi var-kayit yapildi."
  1333. return sonuc
  1334. def vadeleme_kontrol(self,fkod):
  1335. sql=open('./altyapi/sql/vadeleme_kontrol.sql','r').read()
  1336. sql=sql.replace('@fkod@',str(fkod))
  1337. rows=self.calistir(sql)
  1338. if(rows):
  1339. vadelitop=float(rows[0][0])
  1340. gertop=float(rows[0][1])
  1341. return round(vadelitop-gertop,3)
  1342. else:
  1343. return "vadelenecek kriter yok!"
  1344. def fatisko_yap(self,stkno,fatisko,kdvdur):
  1345. fatisko=fatisko.replace(',','.')
  1346. if self.stk_fsb_al(stkno) is None:
  1347. return None
  1348. icra=1
  1349. if(fatisko[0]=='%'):
  1350. fatiskoran=fatisko[1:]
  1351. icra=(100-float(fatiskoran))/100
  1352. else:
  1353. fatisko=float(fatisko)
  1354. tutarfsb=self.stk_fsb_al(stkno)
  1355. if(kdvdur=='E'):
  1356. tutarsda=float(tutarfsb[0].split('=')[1])
  1357. icra=(tutarsda-fatisko)/tutarsda
  1358. else:
  1359. tutarsha=float(tutarfsb[1].split('=')[1])
  1360. icra=(tutarsha-fatisko)/tutarsha
  1361. return self.stk_iskonto(stkno,icra)
  1362. def satisko_icra(self,bf,satisko):
  1363. satiskolar=satisko.split('-')
  1364. for satisko in satiskolar:
  1365. satisko=float(str(satisko).replace(',','.'))
  1366. icra=(100-float(satisko))/100
  1367. bf=float(bf)*icra
  1368. return round(bf,2)
  1369. def fatura_ustbilgi(self,fkod):
  1370. #sql=open('./altyapi/sql/fatura_ustbilgi.sql','r').read()
  1371. sql=codecs.open('./altyapi/sql/fatura_ustbilgi.sql','r','iso-8859_9').read()
  1372. sql=sql.replace('@fkod@',str(fkod))
  1373. rows=self.calistir(sql)
  1374. data=[]
  1375. for rowx in rows:
  1376. data.append(rowx[0])
  1377. data.append(rowx[1])
  1378. data.append(rowx[2][0])
  1379. data.append(rowx[3])
  1380. data.append(rowx[4])
  1381. data.append(rowx[5])
  1382. kaynak=rowx[6]
  1383. kaynakad=self.cari(kaynak).isim
  1384. data.append(kaynakad+"@"+kaynak)
  1385. hedef=rowx[7]
  1386. hedefad=self.cari(hedef).isim
  1387. data.append(hedefad+"@"+hedef)
  1388. data.append(rowx[8])
  1389. data.append(float(rowx[9]))
  1390. data.append(rowx[10])
  1391. data.append(rowx[11])
  1392. data.append(float(rowx[12]))
  1393. data.append(float(rowx[13]))
  1394. data.append(float(rowx[14]))
  1395. data.append(float(rowx[15]))
  1396. data.append(float(rowx[16]))
  1397. data.append(float(rowx[17]))
  1398. data.append(float(rowx[18]))
  1399. data.append(rowx[19])
  1400. data.append(rowx[20])
  1401. data.append(rowx[21])
  1402. data.append(float(rowx[22]))
  1403. data.append(rowx[23])
  1404. data.append(rowx[24])
  1405. return data
  1406. def fatura_bilgi(self,kimlik):
  1407. sqldosya='./altyapi/sql/fatura_bilgi.sql'
  1408. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  1409. sql=sql.replace('@kimlik@',str(kimlik))
  1410. rows=self.calistir(sql)
  1411. return rows
  1412. #salt sql data icin
  1413. #sqldosyadata='./altyapi/sql/sthar_bilgi_data.sql'
  1414. #codecs.open(sqldosyadata,'w','iso-8859_9').write(sql)
  1415. '''print sql
  1416. rapor=statikrapor()
  1417. rapor.sql(sql)
  1418. return rapor.getHtml()'''
  1419. def fatura_sil(self,kimlik):
  1420. sql=open('./altyapi/sql/fatura_sil.sql','r').read()
  1421. sql=sql.replace('@kimlik@',str(kimlik))
  1422. sonuc=self.calis(sql)
  1423. if(sonuc=="tamam"):
  1424. return sonuc
  1425. else:
  1426. return "fatura silinirken vt hatasi"
  1427. def faturaust_sil(self,kimlik):
  1428. sql=open('./altyapi/sql/faturaust_sil.sql','r').read()
  1429. sql=sql.replace('@kimlik@',str(kimlik))
  1430. sonuc=self.calis(sql)
  1431. if(sonuc=="tamam"):
  1432. return sonuc
  1433. else:
  1434. return "fatura silinirken vt hatasi"
  1435. def fiyat_guncelle(self,fkod):
  1436. sql=open('./altyapi/sql/fiyat_guncelle.sql','r').read()
  1437. sql=sql.replace('@fkod@',str(fkod))
  1438. return self.calis(sql)
  1439. def fisno_kontrol(self,fisno):
  1440. sql=open('./altyapi/sql/fisno_kontrol.sql','r').read()
  1441. sql=sql.replace('@fisno@',str(fisno))
  1442. rows=self.calistir(sql)
  1443. if(rows is None):
  1444. return "yok"
  1445. else:
  1446. return "var"
  1447. def fisno_al(self,fkod):
  1448. sql=open('./altyapi/sql/fisno_al.sql','r').read()
  1449. sql=sql.replace('@fkod@',str(fkod))
  1450. rows=self.calistir(sql)
  1451. if(rows is None):
  1452. return "yok"
  1453. else:
  1454. return rows[0][0]
  1455. def fisno_serial(self,onek,caritip):
  1456. sql=open('./altyapi/sql/fisno_serial.sql','r').read()
  1457. sql=sql.replace('@onek@',str(onek))
  1458. sql=sql.replace('@caritip@',str(caritip))
  1459. rows=self.calistir(sql)
  1460. for rowx in rows:
  1461. if(rowx[0] is not None):
  1462. mvcfis=rowx[0]
  1463. mvcfis=mvcfis.split(onek)[1]
  1464. sksm=int(mvcfis)
  1465. sksm1=sksm+1
  1466. mvcfis=mvcfis.replace(str(sksm),str(sksm1))
  1467. yenifis=onek+mvcfis
  1468. #print "yeni:",yenifis
  1469. return yenifis
  1470. else:
  1471. mvcfis=onek
  1472. for i in range(len(onek),9):
  1473. mvcfis+='0'
  1474. mvcfis+='1'
  1475. return mvcfis
  1476. def fisno_serial2(self,onek,gctur):
  1477. print onek,gctur
  1478. onek=onek.upper()
  1479. sql=open('./altyapi/sql/fisno_serial2.sql','r').read()
  1480. sql=sql.replace('@onek@',str(onek))
  1481. sql=sql.replace('@gctur@',str(gctur))
  1482. rows=self.calistir(sql)
  1483. for rowx in rows:
  1484. if(rowx[0] is not None):
  1485. mvcfis=rowx[0]
  1486. mvcfis=mvcfis.split(onek)[1]
  1487. sksm=int(mvcfis)
  1488. sksmy=sksm+1
  1489. eskifissy=str(sksm)
  1490. ek=""
  1491. if len(str(sksm))<len(str(sksmy)):
  1492. fark=len(str(sksmy))-len(str(sksm))
  1493. if fark==1:
  1494. ek="0"
  1495. if fark==2:
  1496. ek="00"
  1497. mvcfis=mvcfis.replace(ek+eskifissy,str(sksmy))
  1498. yenifis=onek+mvcfis
  1499. return yenifis
  1500. else:
  1501. mvcfis=onek
  1502. for i in range(len(onek),9):
  1503. mvcfis+='0'
  1504. mvcfis+='1'
  1505. return mvcfis
  1506. def fatura_islemturu(self,fkod):
  1507. sql=open('./altyapi/sql/fatura_islemturu.sql','r').read()
  1508. sql=sql.replace('@fkod@',str(fkod))
  1509. rows = self.calistir(sql)
  1510. if(rows):
  1511. return rows[0][0]
  1512. else:
  1513. return None
  1514. def spr_yukle(self,sprno):
  1515. sql=open('./altyapi/sql/spr_yukle.sql','r').read()
  1516. sql=sql.replace('@sprno@',str(sprno))
  1517. sprhar=[]
  1518. sprhar=self.calistir(sql)
  1519. return sprhar
  1520. def fatura_yukle(self,fkod):
  1521. tblfatura=Tblfatura()
  1522. sql=open('./altyapi/sql/fatura_yukle.sql','r').read()
  1523. sql=sql.replace('@fkod@',str(fkod))
  1524. fatura=self.calistir(sql)
  1525. tblfatura.yukle(fatura[0])
  1526. #for attr, value in tblfatura.__dict__.iteritems():
  1527. # print attr,value
  1528. return tblfatura
  1529. def sth_yukle(self,incno):
  1530. sthar=Tblsthar()
  1531. sql=open('./altyapi/sql/sth_yukle.sql','r').read()
  1532. sql=sql.replace('@incno@',str(incno))
  1533. row=self.calistir(sql)
  1534. sthar.yukle(row[0])
  1535. #for attr, value in tblfatura.__dict__.iteritems():
  1536. # print attr,value
  1537. return sthar
  1538. def finckeyno_turet(self):
  1539. finckey=0
  1540. finckey=randint(0,999999)
  1541. if(self.finckeyno_kontrol(finckey)=="yok"):
  1542. return finckey
  1543. else:
  1544. self.finckeyno_turet()
  1545. def finckeyno_al(self):
  1546. sql=open('./altyapi/sql/finckeyno_al.sql','r').read()
  1547. rows = self.calistir(sql)
  1548. maxfinc=rows[0][0]
  1549. if(type(maxfinc) is long):
  1550. maxfinc=maxfinc+1
  1551. else:
  1552. maxfinc=1
  1553. return maxfinc
  1554. def finckeyno_kontrol(self,finckeyno):
  1555. sql=open('./altyapi/sql/finckeyno_kontrol.sql','r').read()
  1556. sql=sql.replace('@finckeyno',str(finckeyno))
  1557. rows = self.calistir(sql)
  1558. if(rows):
  1559. return "var"
  1560. else:
  1561. return "yok"
  1562. def stharlist_al(self,stoklistno="xxx"):
  1563. stharlist=[]
  1564. con = lite.connect(self.stoklistvt)
  1565. with con:
  1566. cur = con.cursor()
  1567. sql=open('./altyapi/sql/stharlist_al.sql','r').read()
  1568. sql=sql.replace('@stoklistno',stoklistno)
  1569. cur.execute(sql)
  1570. rows = cur.fetchall()
  1571. for row in rows:
  1572. sthar=Stokhareket()
  1573. sthar.sira=row[0]
  1574. sthar.stkod=row[1]
  1575. sthar.stokad=row[2]
  1576. sthar.miktar=float(row[3])
  1577. sthar.bf=float(row[4])
  1578. sthar.tutar=sthar.miktar*sthar.bf
  1579. sthar.stoklistno=row[6]
  1580. stharlist.append(sthar)
  1581. return stharlist
  1582. def stharlist_goster(self,stoklistno="xxx"):
  1583. stharlist=self.stharlist_al(stoklistno)
  1584. for sthar in stharlist:
  1585. sthar.goster()
  1586. def stharYstk(self,fkod):
  1587. stkno='fkod'+fkod+".stk"
  1588. self.stk_sil(stkno)
  1589. sqldosya='./altyapi/sql/sthar_detay.sql'
  1590. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  1591. sql=sql.replace('@fkod@',fkod)
  1592. rows=self.calistir(sql)
  1593. kdvdurum=self.fatura_kdvdurum(fkod)
  1594. if kdvdurum=="X":
  1595. return "olumsuz"
  1596. if(rows):
  1597. for sthar in rows:
  1598. fiat=""
  1599. if kdvdurum=='H':
  1600. fiat=sthar[5]
  1601. else:
  1602. fiat=sthar[6]
  1603. stharyeni=(sthar[1],sthar[2],float(sthar[3]),float(fiat),float(sthar[7]),stkno)
  1604. self.stk_ekle(stharyeni)
  1605. return stkno
  1606. return "olumsuz"
  1607. def cogul_stkbir(self,fkodlar):
  1608. #str(random.randrange(1,1000))
  1609. #self.stk_sil(stkno)
  1610. stkno=""
  1611. for fkod in fkodlar:
  1612. stkno+=str(fkod)+"@"
  1613. stkno+=".irs"
  1614. for fkod in fkodlar:
  1615. sqldosya='./altyapi/sql/sthar_detay.sql'
  1616. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  1617. sql=sql.replace('@fkod@',str(fkod))
  1618. rows=self.calistir(sql)
  1619. if(rows):
  1620. for sthar in rows:
  1621. stharyeni=(sthar[1],sthar[2],float(sthar[3]),float(sthar[6]),float(sthar[7]),stkno)
  1622. self.stk_ekle(stharyeni)
  1623. return stkno
  1624. def irs_topfat(self,fkodlar,tarih,fisno,kaydeden):
  1625. yenifkod=self.finckeyno_al()
  1626. sqlfatura=codecs.open('./altyapi/sql/tblfatura_ekle.sql','r','iso-8859_9').read()
  1627. tblfatura=Tblfatura()
  1628. for fkod in fkodlar:
  1629. eskifat=self.fatura_ustbilgi(fkod)
  1630. irsdurum=eskifat[11]
  1631. if irsdurum=='E':
  1632. print eskifat
  1633. sqldosya='./altyapi/sql/sth_guncelle.sql'
  1634. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  1635. sql=sql.replace('@fkod@',str(fkod))
  1636. sql=sql.replace('@yenifkod@',str(yenifkod))
  1637. sql=sql.replace('@fisno@',str(fisno))
  1638. self.calis(sql)
  1639. tblfatura.kaynak=eskifat[6].split('@')[1]
  1640. tblfatura.ftip=eskifat[1]
  1641. tblfatura.fno=fisno
  1642. tblfatura.hedef=eskifat[7].split('@')[1]
  1643. tblfatura.tarih=self.tarih_format(tarih)
  1644. tblfatura.khtutar+=float(eskifat[12])
  1645. tblfatura.kdtutar+=float(eskifat[13])
  1646. tblfatura.kdvtoplam+=float(eskifat[17])
  1647. tblfatura.vadetarihi=self.tarih_format(tarih)
  1648. tblfatura.cari_tip=eskifat[19]
  1649. tblfatura.islem_turu=eskifat[20]
  1650. tblfatura.med='E'
  1651. tblfatura.irs='H'
  1652. tblfatura.kdvdurum=eskifat[21]
  1653. tblfatura.fatkalem_adedi+=float(eskifat[18])
  1654. tblfatura.toplam_mik+=eskifat[22]
  1655. tblfatura.geneltoplam+=float(eskifat[9])
  1656. tblfatura.kayityapankul=kaydeden
  1657. tblfatura.duzeltmeyapankul=kaydeden
  1658. tblfatura.kayittarihi=datetime.datetime.now()
  1659. tblfatura.duzeltmetarihi=datetime.datetime.now()
  1660. tblfatura.aciklama=""
  1661. tblfatura.takipkod=""
  1662. tblfatura.inckeyno=yenifkod
  1663. tblfatura.kdv1top+=float(eskifat[14])
  1664. tblfatura.kdv8top+=float(eskifat[15])
  1665. tblfatura.kdv18top+=float(eskifat[16])
  1666. else:
  1667. return "irsaliye olmayan fis hatasi"
  1668. #faturalasan irs in silinmesi
  1669. self.faturaust_sil(fkod)
  1670. faturasql=tblfatura.ekle(sqlfatura)
  1671. self.calistir(faturasql)
  1672. return "tamam"
  1673. def sayim_hazirla(self,stkno,carikod,tarih,satis):
  1674. self.stk_sadelestir(stkno)
  1675. con = lite.connect(self.ayar_al('999','stoklist_db'))
  1676. saykod=str(randint(0,999999))
  1677. if satis=="":
  1678. satis="SAYIM_MODULU"
  1679. #cikis_stkno=carikod+'@'+'CIKIS'+'@'+tarih.split()[0]+"@SYM"
  1680. #giris_stkno=carikod+'@'+'GIRIS'+'@'+tarih.split()[0]+"@SYM"
  1681. tarih=self.tarih_format(tarih)
  1682. cikis_stkno=carikod+'@'+str(satis)+'@sayim'+saykod+'@CIKIS'+'@'+tarih.split()[0]+".sym"
  1683. giris_stkno=carikod+'@'+str(satis)+'@sayim'+saykod+'@GIRIS'+'@'+tarih.split()[0]+".sym"
  1684. #ustune yazmaz eski sayim hazir stksini siler.
  1685. self.stk_sil(cikis_stkno)
  1686. self.stk_sil(giris_stkno)
  1687. sql=open('./altyapi/sql/stok_bakiye.sql','r').read()
  1688. sql=sql.replace('@tarih@',tarih)
  1689. sql=sql.replace('@merkez@',carikod)
  1690. sqltemel=sql
  1691. stharlar=self.stharlist_al(stkno)
  1692. for sthar in stharlar:
  1693. stokod=self.stok(sthar.stkod).kod
  1694. stokad=sthar.stokad
  1695. miktar=sthar.miktar
  1696. bf=sthar.bf
  1697. sql=sql.replace('@stokod@',stokod)
  1698. netc=self.calistir(sql)
  1699. bakiye=0.0
  1700. if netc:
  1701. gcbak=netc[0][0]
  1702. if gcbak:
  1703. bakiye=float(gcbak)
  1704. satilan=bakiye-miktar
  1705. tutar=round(bf*satilan,2)
  1706. stkno=""
  1707. if satilan!=0:
  1708. if(satilan>0):
  1709. stkno=cikis_stkno
  1710. else:
  1711. stkno=giris_stkno
  1712. satilan=satilan*-1
  1713. tutar=tutar*-1
  1714. stokhar=(stokod,stokad,satilan,bf,tutar,stkno)
  1715. self.stk_ekle(stokhar)
  1716. sql=sqltemel
  1717. return "tamam"
  1718. def sayim_islet(self,stkno,kaydeden):
  1719. now = datetime.datetime.now()
  1720. stk=stkno.split('@')
  1721. carikod=str(stk[0])
  1722. yon=stk[1]
  1723. tarih=stk[2]
  1724. tarih=str(tarih)
  1725. #tarih=tarih.replace('-','.')
  1726. kdvsi=0.0
  1727. sonek=str(randint(1000,9999))
  1728. sayack="SAYIM"+carikod+'_'+sonek
  1729. fisno="s_"+carikod+'_'+sonek
  1730. sayim_fatura=Fatura()
  1731. sayim_fatura.tarih=tarih
  1732. sayim_fatura.vadetarih=tarih
  1733. sayim_fatura.fisno=fisno
  1734. if(yon=='GIRIS'):
  1735. sayim_fatura.fattip="G"
  1736. sayim_fatura.kaynak=carikod
  1737. sayim_fatura.hedef="SAYIM_MODULU"
  1738. else:
  1739. sayim_fatura.fattip="C"
  1740. sayim_fatura.kaynak=carikod
  1741. sayim_fatura.hedef="SAYIM_MODULU"
  1742. sayim_fatura.stharlistno=stkno
  1743. sayim_fatura.kdvdurum="E"
  1744. sayim_fatura.aciklama=sayack
  1745. sayim_fatura.islem="F"
  1746. sayim_fatura.tutar=0
  1747. sayim_fatura.med='H'
  1748. sayim_fatura.irs='H'
  1749. sayim_fatura.kaydeden=kaydeden
  1750. sayim_fatura.vadesay=1
  1751. sayim_fatura.takipkod=''
  1752. sonuc=self.faturalama(sayim_fatura,'sayim')
  1753. sonuc2="sayim vt hatasi"
  1754. if(sonuc=='tamam'):
  1755. sonuc2=self.fatura_sil('0')
  1756. return sonuc2
  1757. def stok_sifirla(self,carikod,tarih,kriter="",aranan="",dizi=None):
  1758. con = lite.connect(self.ayar_al('999','stoklist_db'))
  1759. tarih=self.tarih_format(tarih)
  1760. saykod=str(randint(0,999999))
  1761. cikis_stkno=carikod+'@SAYIM_MODULU@sym'+saykod+'@CIKIS'+'@'+tarih.split()[0]+"@.stk"
  1762. giris_stkno=carikod+'@SAYIM_MODULU@sym'+saykod+'@GIRIS'+'@'+tarih.split()[0]+"@.stk"
  1763. self.stk_sil(cikis_stkno)
  1764. self.stk_sil(giris_stkno)
  1765. sql=open('./altyapi/sql/stok_bakiye.sql','r').read()
  1766. sql=sql.replace('@tarih@',tarih)
  1767. sql=sql.replace('@merkez@',carikod)
  1768. sqltemel=sql
  1769. eksorgu=""
  1770. if(kriter!=""):
  1771. eksorgu=" and sb."+kriter+" like '%"+str(aranan)+"%'"
  1772. #ilgili stokların stok kodlarinin cekilmesi
  1773. sqlbak=open('./altyapi/sql/stok_sifirla.sql','r').read()
  1774. sqlbak=sqlbak.replace('@tarih@',tarih)
  1775. sqlbak=sqlbak.replace('@carikod@',carikod)
  1776. sqlbak=sqlbak.replace('@eksorgu@',eksorgu)
  1777. stoklist=self.calistir(sqlbak)
  1778. #print stoklist,sqltemel,sqlbak
  1779. if dizi:
  1780. stoklist=dizi
  1781. if(stoklist):
  1782. for stokod in stoklist:
  1783. stokod=stokod[0]
  1784. stok=self.stok(stokod)
  1785. bf=stok.satis_fiat3
  1786. sql=sql.replace('@stokod@',stokod)
  1787. netc=self.calistir(sql)
  1788. print stokod
  1789. if(netc):
  1790. bakiye=netc[0][0]
  1791. if bakiye:
  1792. bakiye=float(str(bakiye))
  1793. else:
  1794. bakiye=0
  1795. else:
  1796. bakiye=0.0
  1797. tutar=round(bf*bakiye,2)
  1798. stkno=""
  1799. if(bakiye>0):
  1800. stkno=cikis_stkno
  1801. else:
  1802. bakiye=bakiye*-1
  1803. tutar=tutar*-1
  1804. stkno=giris_stkno
  1805. stokhar=(stokod,stok.isim,bakiye,bf,tutar,stkno)
  1806. with con:
  1807. cur = con.cursor()
  1808. cur.execute("INSERT INTO stoklist (stkod,stkad,miktar,bf,tutar,stoklistno) VALUES(?, ?,?, ?, ?,?)", stokhar)
  1809. sql=sqltemel
  1810. return "tamam"
  1811. else:
  1812. return "ilgili stokların hareket kaydı yok!"
  1813. def dizin_cek(self,dizin='rapor',uzanti="",anadizin="altyapi"):
  1814. dizinyol='./'+anadizin+'/'+dizin
  1815. flst=[]
  1816. lst=os.listdir(dizinyol)
  1817. if uzanti=="":
  1818. return sorted(lst)
  1819. else:
  1820. for dosya in lst:
  1821. if dosya.endswith("."+uzanti):
  1822. flst.append(dosya)
  1823. return sorted(flst)
  1824. def sql_al(self,dizin,dosya):
  1825. sqlyol='./altyapi/'+dizin+'/'+dosya
  1826. sql=codecs.open(sqlyol,'r','iso-8859_9').read()
  1827. return sql
  1828. def sql_kaydet(self,dizin,dosya,kod,kayitmodu):
  1829. sqlyol='./altyapi/'+dizin+'/'+dosya
  1830. try:
  1831. codecs.open(sqlyol,"w",'iso-8859_9').write(kod)
  1832. return "tamam"
  1833. except Exception,e:
  1834. print str(e)
  1835. return "sql kayit hatasi:sorunlu yol"
  1836. def param_guncelle(self,dosya,paramlar,dizin='rapor'):
  1837. sqlyol='./altyapi/'+dizin+'/'+dosya
  1838. prm=""
  1839. param=paramlar.split('set ')
  1840. for par in param:
  1841. if par!="":
  1842. prm+="set "+par+";"+"\n"
  1843. kod=codecs.open(sqlyol,'r','iso-8859_9').read()
  1844. oz=kod.split('#sql')[1]
  1845. yenikod=prm+oz
  1846. print yenikod
  1847. return yenikod
  1848. def rapor_paramlar(self,dosya,dizin='rapor'):
  1849. sqlyol='./altyapi/'+dizin+'/'+dosya
  1850. paramlar=""
  1851. try:
  1852. kod=codecs.open(sqlyol,'r','iso-8859_9').read()
  1853. kod=kod.split('#sql')[0]
  1854. kod=kod.split(';')
  1855. for kodsat in kod:
  1856. kodsat=kodsat.lower()
  1857. kodsat=kodsat.strip()
  1858. if kodsat.startswith("set ") or kodsat.startswith("#"):
  1859. paramlar+=kodsat+"\n"
  1860. return paramlar
  1861. except Exception,e:
  1862. print str(e)
  1863. def etoYstk(self,dosya):
  1864. data=[]
  1865. stkno=dosya.split("/")[1]+".stk"
  1866. self.stk_sil(stkno)
  1867. jsondata=open(dosya,"r").read()
  1868. data=json.loads(jsondata)
  1869. print data
  1870. sayac=0
  1871. rapor=""
  1872. for dat in data:
  1873. if sayac!=0:
  1874. stkod=str(dat[0])
  1875. stkad=str(dat[1])
  1876. if stkod=="":
  1877. stkod="---"
  1878. if stkad=="":
  1879. stkad="***"
  1880. kostok=self.stok(stkod)
  1881. kostok2=self.stok2(stkad)
  1882. print "---",stkod,stkad
  1883. stokbul=0
  1884. if (kostok):
  1885. stkod=kostok.kod
  1886. stkad=kostok.isim
  1887. print "kod_tanimli",kostok.kod,kostok.isim
  1888. stokbul=1
  1889. elif (kostok2):
  1890. stkod=kostok2.kod
  1891. stkad=kostok2.isim
  1892. print "isim_tanimli",kostok2.kod,kostok2.isim
  1893. stokbul=1
  1894. else:
  1895. rapor+=stkod+":"+stkad+","
  1896. if stokbul==1:
  1897. miktar=0
  1898. bf=0
  1899. if dat[2]!="" and dat[2]:
  1900. ms=dat[2]
  1901. ms=ms.replace(",",".")
  1902. miktar=float(ms)
  1903. if dat[3]!="" and dat[3]:
  1904. if dat[3]=="-1":
  1905. bf=self.stok(stkod).satis_fiat3
  1906. elif dat[3]=="-2":
  1907. bf=self.stok(stkod).satis_fiat2
  1908. else:
  1909. bfs=dat[3]
  1910. bfs=bfs.replace(",",".")
  1911. bf=float()
  1912. tutar=miktar*bf
  1913. if miktar !=0:
  1914. stharyeni=(stkod,stkad,miktar,bf,tutar,stkno)
  1915. self.stk_ekle(stharyeni)
  1916. sayac+=1
  1917. if rapor=="":
  1918. return "tamam"
  1919. else:
  1920. return rapor
  1921. def stk_sadelestir(self,stkno):
  1922. print stkno+" stk sadelestiriliyor....."
  1923. ax = datetime.datetime.now()
  1924. con = lite.connect("stoklist.db")
  1925. with con:
  1926. cur = con.cursor()
  1927. sql="insert into stoklist(stkod,stkad,miktar,bf,tutar,stoklistno) select * from (SELECT stkod,stkad,sum(miktar) as toplam,bf,sum(miktar)*bf as tutar,stoklistno FROM stoklistgcc where stoklistno='"+stkno+"' group by stkad,bf order by stkod) as t where toplam > 0 "
  1928. cur.execute(sql)
  1929. cur.execute("delete FROM stoklistgcc where stoklistno='"+stkno+"'")
  1930. ay = datetime.datetime.now()
  1931. print "stk sadelestirildi. ",(ay-ax).total_seconds()," saniye surdu."
  1932. def gtfYstk(self,gtfdos,poscari,merkez):
  1933. print "gtf --> stk donusumu yapiliyor..."
  1934. stokads=self.stoklar_ads()
  1935. anastk=[]
  1936. sthar=[]
  1937. s=0
  1938. sgec=0
  1939. hata='yok'
  1940. '''
  1941. trh=gtfdos.split('@')[0]
  1942. trh=self.tarih_format(trh)
  1943. trh=trh.split()[0]
  1944. stkno=poscari+"@POS@x@SATIS@"+trh+".stk"
  1945. '''
  1946. with open(gtfdos,'r') as f:
  1947. for ikstr in f:
  1948. ikstr=ikstr.split()
  1949. stra=ikstr[0]
  1950. if stra != "SIGNATURE=GNDSALES.GDF":
  1951. trh=ikstr[2]
  1952. trh=self.tarih_format(trh)
  1953. trh=trh.split()[0]
  1954. stkno=poscari+"@POS@x@SATIS@"+trh+".st2"
  1955. break
  1956. with open(gtfdos,'r') as f:
  1957. for line in f:
  1958. line=line.split()
  1959. islemtip=line[0]
  1960. if(islemtip=='01'):
  1961. gecerli=line[7]
  1962. if(islemtip=='02' and gecerli=='00'):
  1963. stokod=line[2]
  1964. iptal=line[3]
  1965. miktar=line[6]
  1966. miktar=miktar.replace(',','.')
  1967. miktar=float(miktar)
  1968. if(iptal=='10'):
  1969. miktar=miktar*-1
  1970. olcubr=line[7][0]
  1971. if(olcubr=='1'):
  1972. miktar=miktar/1000
  1973. bf= line[7][1:]
  1974. bf=bf.replace(',','.')
  1975. bf=float(bf)
  1976. isk= line[10]
  1977. tutar=line[8]
  1978. tutar=tutar.replace(',','.')
  1979. tutar=float(tutar)
  1980. if(isk!='0'):
  1981. isk=isk.replace(',','.')
  1982. isk=float(isk)
  1983. tutar=tutar-isk
  1984. bf=tutar/miktar
  1985. #bf=round(bf,3)
  1986. tutar=bf*miktar
  1987. #tutar=round(tutar,3)
  1988. #if(stok not in anastk):
  1989. if(stokod in stokads and stokads[stokod]):
  1990. stokad=str(stokads[stokod])
  1991. sthar=[stokod,stokad,miktar,bf,tutar,stkno]
  1992. #print stokod
  1993. else:
  1994. sthar=None
  1995. print 'stok kodlu urun bulunamadi:',stokod
  1996. l.yaz("POS AKTARIM HATASI: "+stokod+" stok kodlu urun bulunamadi")
  1997. hata='var'
  1998. break
  1999. anastk.append(sthar)
  2000. sgec+=1
  2001. if(hata=='yok'):
  2002. odemeler=self.gtf_analiz(gtfdos)
  2003. kasa=odemeler[0]
  2004. kredi=odemeler[1]
  2005. veresiye=odemeler[2]
  2006. odemeler=[]
  2007. cariler=self.ayar_al('999',poscari+'_poscari')
  2008. kasa_cari=cariler[0]
  2009. kasa_odemestk=kasa_cari+"@POS"+"@x@KGIRIS@"+trh+".st2"
  2010. sthar=["NAKIT","NAKIT",1,kasa,kasa,kasa_odemestk]
  2011. odemeler.append(sthar)
  2012. kredi_cari=cariler[1]
  2013. kredi_odemestk=merkez+"@"+kredi_cari+"@x@KCIKIS@"+trh+".st2"
  2014. sthar=["NAKIT","NAKIT",1,kredi,kredi,kredi_odemestk]
  2015. odemeler.append(sthar)
  2016. veresiye_cari=cariler[2]
  2017. veresiye_odemestk=merkez+"@"+veresiye_cari+"@x@KCIKIS@"+trh+".st2"
  2018. sthar=["NAKIT","NAKIT",1,veresiye,veresiye,veresiye_odemestk]
  2019. odemeler.append(sthar)
  2020. con = lite.connect(self.ayar_al('999','stoklist_db'))
  2021. cur = con.cursor()
  2022. with con:
  2023. for stokhar in anastk:
  2024. cur.execute("INSERT INTO stoklistgcc (stkod,stkad,miktar,bf,tutar,stoklistno) VALUES(?, ?,?, ?, ?,?)", stokhar)
  2025. for stokhar2 in odemeler:
  2026. cur.execute("INSERT INTO stoklist (stkod,stkad,miktar,bf,tutar,stoklistno) VALUES(?, ?,?, ?, ?,?)", stokhar2)
  2027. print "donusum datasi cevriliyor....."
  2028. self.stk_sadelestir(stkno)
  2029. print "pos > stk islemi bitti."
  2030. return "tamam"
  2031. else:
  2032. return "hata"
  2033. def pos_urunliste(self,kriter,aranan):
  2034. pos_dizin="./pos/"#self.ayar_al('999','pos_dizin')
  2035. pos_dizin_sablon="./pos/sablon/"#self.ayar_al('999','pos_dizin_sablon')
  2036. dosya=open(pos_dizin+"/"+'GNCPLUF.GTF','w')
  2037. urunlist="SIGNATURE=GNDPLU.GDF"+"\n"
  2038. stoklar=self.stoklar_pos(kriter,aranan)
  2039. for stok in stoklar:
  2040. stkod=stok[0]
  2041. stkad=stok[1]
  2042. stkad=stkad.upper()
  2043. stkadks=stkad[0:20]
  2044. sf1=stok[2]
  2045. sf1=round(sf1,2)
  2046. sf1=str(sf1)
  2047. sf1=sf1.replace('.',',')
  2048. sf2=stok[3]
  2049. sf2=round(sf2,2)
  2050. sf2=str(sf2)
  2051. sf2=sf2.replace('.',',')
  2052. sf3=stok[4]
  2053. sf3=round(sf3,2)
  2054. sf3=str(sf3)
  2055. sf3=sf3.replace('.',',')
  2056. kdvoran=stok[5]
  2057. kdvkod=""
  2058. if(kdvoran==0.00):
  2059. kdvkod='00'
  2060. if(kdvoran==1.00):
  2061. kdvkod='03'
  2062. if(kdvoran==8.00):
  2063. kdvkod='01'
  2064. if(kdvoran==18.00):
  2065. kdvkod='02'
  2066. if(str(stok[6])!='NULL'):
  2067. orta_sabit=open(pos_dizin_sablon+"pos_orta_sabit.pos",'r').read()
  2068. son_sabit=open(pos_dizin_sablon+"pos_son_sabit.pos",'r').read()
  2069. orta_sabit=orta_sabit.replace('@grupkod@',str(stok[6]))
  2070. if(str(stok[7]).upper() in ['KG','GR','LT']):
  2071. orta_sabit=orta_sabit.replace('@olcubr@','11000')
  2072. son_sabit=son_sabit.replace('@olcubr@','10')
  2073. else:
  2074. orta_sabit=orta_sabit.replace('@olcubr@','01 ')
  2075. son_sabit=son_sabit.replace('@olcubr@','00')
  2076. son_sabit=son_sabit.replace('@kdv@',kdvkod)
  2077. for i in range(0,403):
  2078. if(i==0):
  2079. urunlist+="01 1"+stkod.upper()
  2080. if(i<30 and i>5+len(stkod)):
  2081. urunlist+=" "
  2082. if(i==31):
  2083. urunlist+=stkod.upper()
  2084. if(i==55):
  2085. urunlist+=stkad
  2086. if(i<54 and i>29+len(stkod)):
  2087. urunlist+=" "
  2088. if(i==135):
  2089. urunlist+=stkadks
  2090. if(i<135 and i>54+len(stkad)):
  2091. urunlist+=" "
  2092. if(i==190):
  2093. urunlist+=orta_sabit
  2094. if(i<190 and i>133+len(stkadks)):
  2095. urunlist+=" "
  2096. if(i==356):
  2097. urunlist+=sf1
  2098. if(i<371 and i>355+len(sf1)):
  2099. urunlist+=" "
  2100. if(i==370):
  2101. urunlist+=sf2
  2102. if(i<386 and i>370+len(sf2)):
  2103. urunlist+=" "
  2104. if(i==386):
  2105. urunlist+=sf3
  2106. if(i==401):
  2107. urunlist+=son_sabit
  2108. if(i<401 and i>385+len(sf3)):
  2109. urunlist+=" "
  2110. '''
  2111. if(i==356):
  2112. urunlist+=sf1
  2113. if(i<370 and i>355+len(sf1)):
  2114. urunlist+=" "
  2115. if(i==371):
  2116. urunlist+=sf2
  2117. if(i<386 and i>370+len(sf2)):
  2118. urunlist+=" "
  2119. if(i==386):
  2120. urunlist+=sf3
  2121. if(i==401):
  2122. urunlist+=son_sabit
  2123. if(i<401 and i>385+len(sf3)):
  2124. urunlist+=" "
  2125. '''
  2126. #stoka ait barkodlarin ayarlanmasi
  2127. barkodlist=""
  2128. urunlist+="\n"
  2129. barkod1=stok[8]
  2130. if(barkod1!="" and barkod1!="NULL"):
  2131. for j in range(0,90):
  2132. if(j==0):
  2133. barkodlist+="02 1"+stkod.upper()
  2134. if(j<30 and j>5+len(stkod)):
  2135. barkodlist+=" "
  2136. if(j==31):
  2137. barkodlist+=barkod1
  2138. if(j==55):
  2139. barkodlist+=barkod1
  2140. if(j<54 and j>29+len(barkod1)):
  2141. barkodlist+=" "
  2142. if(j==78):
  2143. barkodlist+="1 001"
  2144. if(j<77 and j>52+len(barkod1)):
  2145. barkodlist+=" "
  2146. urunlist+=barkodlist+"\n"
  2147. barkodlist=""
  2148. barkod2=stok[9]
  2149. if(barkod2!="" and barkod2!="NULL"):
  2150. for j in range(0,90):
  2151. if(j==0):
  2152. barkodlist+="02 1"+stkod.upper()
  2153. if(j<30 and j>5+len(stkod)):
  2154. barkodlist+=" "
  2155. if(j==31):
  2156. barkodlist+=barkod2
  2157. if(j==55):
  2158. barkodlist+=barkod2
  2159. if(j<54 and j>29+len(barkod2)):
  2160. barkodlist+=" "
  2161. if(j==78):
  2162. barkodlist+="1 002"
  2163. if(j<77 and j>52+len(barkod2)):
  2164. barkodlist+=" "
  2165. urunlist+=barkodlist+"\n"
  2166. barkodlist=""
  2167. barkod3=stok[10]
  2168. if(barkod3!="" and barkod3!="NULL"):
  2169. for j in range(0,90):
  2170. if(j==0):
  2171. barkodlist+="02 1"+stkod.upper()
  2172. if(j<30 and j>5+len(stkod)):
  2173. barkodlist+=" "
  2174. if(j==31):
  2175. barkodlist+=barkod3
  2176. if(j==55):
  2177. barkodlist+=barkod3
  2178. if(j<54 and j>29+len(barkod3)):
  2179. barkodlist+=" "
  2180. if(j==78):
  2181. barkodlist+="1 003"
  2182. if(j<77 and j>52+len(barkod3)):
  2183. barkodlist+=" "
  2184. urunlist+=barkodlist+"\n"
  2185. barkodlist=""
  2186. barkod4=stok[11]
  2187. if(barkod4!="" and barkod4!="NULL"):
  2188. for j in range(0,90):
  2189. if(j==0):
  2190. barkodlist+="02 1"+stkod.upper()
  2191. if(j<30 and j>5+len(stkod)):
  2192. barkodlist+=" "
  2193. if(j==31):
  2194. barkodlist+=barkod4
  2195. if(j==55):
  2196. barkodlist+=barkod4
  2197. if(j<54 and j>29+len(barkod4)):
  2198. barkodlist+=" "
  2199. if(j==78):
  2200. barkodlist+="1 004"
  2201. if(j<77 and j>52+len(barkod4)):
  2202. barkodlist+=" "
  2203. urunlist+=barkodlist+"\n"
  2204. barkodlist=""
  2205. barkod5=stok[12]
  2206. if(barkod5!="" and barkod5!="NULL"):
  2207. for j in range(0,90):
  2208. if(j==0):
  2209. barkodlist+="02 1"+stkod.upper()
  2210. if(j<30 and j>5+len(stkod)):
  2211. barkodlist+=" "
  2212. if(j==31):
  2213. barkodlist+=barkod5
  2214. if(j==55):
  2215. barkodlist+=barkod5
  2216. if(j<54 and j>29+len(barkod5)):
  2217. barkodlist+=" "
  2218. if(j==78):
  2219. barkodlist+="1 005"
  2220. if(j<77 and j>52+len(barkod5)):
  2221. barkodlist+=" "
  2222. urunlist+=barkodlist+"\n"
  2223. barkodlist=""
  2224. barkod6=stok[13]
  2225. if(barkod6!="" and barkod6!="NULL"):
  2226. for j in range(0,90):
  2227. if(j==0):
  2228. barkodlist+="02 1"+stkod.upper()
  2229. if(j<30 and j>5+len(stkod)):
  2230. barkodlist+=" "
  2231. if(j==31):
  2232. barkodlist+=barkod6
  2233. if(j==55):
  2234. barkodlist+=barkod6
  2235. if(j<54 and j>29+len(barkod6)):
  2236. barkodlist+=" "
  2237. if(j==78):
  2238. barkodlist+="1 006"
  2239. if(j<77 and j>52+len(barkod6)):
  2240. barkodlist+=" "
  2241. urunlist+=barkodlist+"\n"
  2242. barkodlist=""
  2243. dosya.write(urunlist)
  2244. return "0"
  2245. def tarih_format(self,tarih):
  2246. tarih=tarih.replace('.','-')
  2247. tarih=tarih.replace(',','-')
  2248. tarih=tarih.replace('/','-')
  2249. tarih=tarih.split('-')
  2250. #enttarih=tarih[2][2:4]+tarih[1]+tarih[0]
  2251. tarih=tarih[2]+"-"+tarih[1]+"-"+tarih[0]
  2252. tarih=str(tarih)
  2253. tarih=tarih+" 00:00:00"
  2254. return tarih
  2255. def tarih_turk(self,tarih):
  2256. tarih=str(tarih)
  2257. tarih=tarih.split()
  2258. tarih=tarih[0]
  2259. tarih=tarih.split('-')
  2260. tarih=tarih[2]+"-"+tarih[1]+"-"+tarih[0]
  2261. tarih=str(tarih)
  2262. return tarih
  2263. def calistir(self,sql):
  2264. #print sql
  2265. con=""
  2266. sqlparca=""
  2267. try:
  2268. con = pymysql.connect(baglanti.host, baglanti.kullanici,baglanti.sifre,baglanti.vt,charset='latin5')
  2269. #con.set_character_set('latin5')
  2270. cur = con.cursor()
  2271. #print "mysqlmak.py-baglanti acildi"
  2272. sql=sql.split(';')
  2273. for sqlparca in sql:
  2274. cur.execute(sqlparca)
  2275. rows = cur.fetchall()
  2276. if(rows):
  2277. rows=list(rows)
  2278. if con:
  2279. #print "mysqlmak.py-baglanti kapandi-select islemi"
  2280. con.close()
  2281. return rows
  2282. if con:
  2283. #print "mysqlmak.py-baglanti kapandi-select islemi"
  2284. con.close()
  2285. #00:23 06.02.2014
  2286. except :
  2287. print "mysqlmak.py-HATA:",str(sys.exc_info()[1])
  2288. if con:
  2289. print "baglanti kapandi-select islemi"
  2290. con.close()
  2291. def calis(self,sql):
  2292. #print sql
  2293. hata=""
  2294. sql=sql.split(';')
  2295. try:
  2296. con = pymysql.connect(baglanti.host, baglanti.kullanici,baglanti.sifre,baglanti.vt,charset='latin5')
  2297. #con.set_character_set('latin5')
  2298. cur = con.cursor()
  2299. for sqlparca in sql:
  2300. cur.execute(sqlparca)
  2301. except:
  2302. hata=sys.exc_info()[1]
  2303. if(hata[1]=='Query was empty'):
  2304. con.commit()
  2305. else:
  2306. con.rollback()
  2307. print "SQL CALISTIRMA HATASI:",str(sys.exc_info()[1])
  2308. return str(sys.exc_info()[1])
  2309. if con:
  2310. con.close()
  2311. '''if(hata[1]=='Query was empty'):
  2312. self.conn.commit()
  2313. return "tamam"
  2314. else:
  2315. self.conn.rollback()
  2316. print str(sys.exc_info()[1])'''
  2317. return "tamam"
  2318. def yaziyla(self,tutar):
  2319. yazi=[]
  2320. if(tutar.find(",") != -1):
  2321. tumtutar = tutar.split(",")
  2322. yaziyla1 = cevir(tumtutar[0]) + "TL"
  2323. yaziyla2 = cevir(tumtutar[1]) + "KRStur"
  2324. elif(tutar.find(".") != -1):
  2325. tumtutar = tutar.split(".")
  2326. yaziyla1 = cevir(tumtutar[0]) + "TL."
  2327. yaziyla2 = cevir(tumtutar[1]) + "KRStur"
  2328. else:
  2329. yaziyla1 = cevir(tutar) + "TLdir"
  2330. yaziyla2 = ""
  2331. yazi.append(yaziyla1)
  2332. yazi.append(yaziyla2)
  2333. return yazi
  2334. def carikod_degistir(self,eskikod,yenikod):
  2335. sqldosya='./altyapi/sql/carikod_degistir.sql'
  2336. sql=codecs.open(sqldosya,'r','iso-8859_9').read()
  2337. sql=sql.replace('@eskikod@',eskikod)
  2338. sql=sql.replace('@yenikod@',yenikod)
  2339. sonuc=self.calis(sql)
  2340. return sonuc
  2341. def cari_yaslandirma(self,iscari,hedef,tarih=""):
  2342. simdiki_zaman=datetime.datetime.now()
  2343. if tarih=="":
  2344. tarih =simdiki_zaman
  2345. else:
  2346. tarih=self.tarih_format(tarih)
  2347. sql=open('./altyapi/sql/cari_borc_liste.sql','r').read()
  2348. sql=sql.replace('@hedef@',str(hedef))
  2349. sql=sql.replace('@vade_tarihi@',str(tarih))
  2350. #open("./sql_cikti/yaslandirma.sql",'w').write(sql)
  2351. #print sql
  2352. vagebolar=self.calistir(sql)
  2353. sql=open('./altyapi/sql/cari_borc_top.sql','r').read()
  2354. sql=sql.replace('@hedef@',str(hedef))
  2355. sql=sql.replace('@vade_tarihi@',str(tarih))
  2356. vagebot=self.calistir(sql)[0][0]
  2357. if(vagebot):
  2358. vagebot=float(str(vagebot))
  2359. #print "topborc",vagebot
  2360. #07:30 17.01.2015
  2361. #iscariler=iscari.split(',')
  2362. #iscari=""
  2363. #for cari in iscariler:
  2364. # iscari+="'"+cari+"',"
  2365. #iscari="'"+iscari[1:len(iscari)-2]+"'"
  2366. sql=open('./altyapi/sql/cari_toplam_cikis.sql','r').read()
  2367. sql=sql.replace('@kaynak@',str(iscari))
  2368. sql=sql.replace('@hedef@',str(hedef))
  2369. sql=sql.replace('@vade_tarihi@',str(tarih))
  2370. open("./sql_cikti/yaslandirma2_data.sql",'w').write(sql)
  2371. odemetop=self.calistir(sql)
  2372. odemetop=odemetop[0][0]
  2373. if odemetop is None:
  2374. odemetop=0
  2375. else:
  2376. odemetop=float(str(odemetop))
  2377. #print "odediimiz top",odemetop
  2378. vadelimit=0
  2379. vadegecler=[]
  2380. #vadesi gecenlerde borc kadar olan kayitlari bulmak
  2381. for vagebo in vagebolar:
  2382. vageborc=float(vagebo[1])
  2383. #print "odenecek",vageborc
  2384. odemetop=float('{0:.2f}'.format(odemetop))
  2385. vageborc=float('{0:.2f}'.format(vageborc))
  2386. kalanodeme=odemetop-vageborc
  2387. eko='{0:.20f}'.format(kalanodeme)
  2388. if eko[0:5]=="-0.00":
  2389. print "zz",kalanodeme
  2390. kalanodeme=0
  2391. if(kalanodeme<0 and odemetop!=0):
  2392. kalanborc=kalanodeme*-1
  2393. odemetop=0
  2394. else:
  2395. kalanborc=vageborc
  2396. if odemetop>=vageborc:
  2397. odemetop=kalanodeme
  2398. else:
  2399. diff=vagebo[2]-simdiki_zaman
  2400. ftrh=str(vagebo[0]).split()[0]
  2401. ftutar=float(vagebo[1])
  2402. vtrh=str(vagebo[2]).split()[0]
  2403. vadegecler.append([ftrh,vtrh,ftutar,kalanborc,diff.days])
  2404. else:
  2405. return "rapor yok"
  2406. #for vadegec in vadegecler:
  2407. rapor=statikrapor()
  2408. dizibas=['fatura','vade','fatura tutar','geciken tutar','gun']
  2409. top_sutlar=[-1,-1,-1,3]
  2410. rapor_html=rapor.diziYhtml(vadegecler,dizibas,top_sutlar)
  2411. return rapor_html
  2412. def sube_cariler(self,merkez):
  2413. sql=open('./altyapi/sql/sube_cariler.sql','r').read()
  2414. sql=sql.replace('@merkez@',str(merkez))
  2415. cariler=self.calistir(sql)
  2416. cr=[]
  2417. for cari in cariler:
  2418. cr.append(cari[0])
  2419. return cr
  2420. def iban_dokum(self):
  2421. sql=open('./altyapi/sql/iban_dokum.sql','r').read()
  2422. rapor=statikrapor()
  2423. topsut=[9,9,2,3]
  2424. rapor.sql(sql,rapbas="IBAN RAPORU",alt=1,topsut=topsut)
  2425. sonuc=rapor.getHtml()
  2426. return sonuc
  2427. def cari_borc_dokum(self,merkez,tarih=""):
  2428. kaynak=merkez
  2429. #kaynak=self.sube_cariler(merkez)
  2430. #kaynak=self.diziYstr_dizi(str(kaynak))
  2431. simdiki_zaman=datetime.datetime.now()
  2432. if tarih=="":
  2433. tarih =simdiki_zaman
  2434. else:
  2435. tarih=self.tarih_format(tarih)
  2436. sql=open('./altyapi/sql/cari_borc_dokum.sql','r').read()
  2437. sql=sql.replace('@kaynak@',str(kaynak))
  2438. sql=sql.replace('@vade_tarihi@',str(tarih))
  2439. codecs.open('sql_cikti/cari_borc_dokum_data.sql','w','iso-8859_9').write(sql)
  2440. rapor=statikrapor()
  2441. topsut=[9,9,2,3]
  2442. rapor.sql(sql,rapbas="BORC RAPORU",alt=1,topsut=topsut)
  2443. sonuc=rapor.getHtml()
  2444. sql2=open('./altyapi/sql/cari_alacak_dokum.sql','r').read()
  2445. sql2=sql2.replace('@kaynak@',str(kaynak))
  2446. sql2=sql2.replace('@vade_tarihi@',str(tarih))
  2447. codecs.open('sql_cikti/cari_alacak_dokum_data.sql','w','iso-8859_9').write(sql2)
  2448. rapor2=statikrapor()
  2449. topsut2=[9,9,2,3]
  2450. rapor2.sql(sql2,rapbas="ALACAK RAPORU",alt=1,topsut=topsut2)
  2451. sonuc2=rapor2.getHtml()
  2452. sql3=open('./altyapi/sql/cari_alacak_dokum_per.sql','r').read()
  2453. sql3=sql3.replace('@kaynak@',str(kaynak))
  2454. sql3=sql3.replace('@vade_tarihi@',str(tarih))
  2455. codecs.open('sql_cikti/cari_alacak_dokumper_data.sql','w','iso-8859_9').write(sql3)
  2456. rapor3=statikrapor()
  2457. topsut3=[9,9,2,3]
  2458. rapor3.sql(sql3,rapbas="PERSONEL HESAPLARI",alt=1,topsut=topsut3)
  2459. sonuc3=rapor3.getHtml()
  2460. sql4=open('./altyapi/sql/cari_alacak_dokum_seyyar.sql','r').read()
  2461. sql4=sql4.replace('@kaynak@',str('seyyar'))
  2462. sql4=sql4.replace('@vade_tarihi@',str(tarih))
  2463. codecs.open('sql_cikti/cari_alacak_dokumseyyar_data.sql','w','iso-8859_9').write(sql4)
  2464. rapor4=statikrapor()
  2465. topsut4=[9,9,2,3]
  2466. rapor4.sql(sql4,rapbas="SEYYAR SATICI CARILERI",alt=1,topsut=topsut4)
  2467. sonuc4=rapor4.getHtml()
  2468. htmlrp="<table><tr><td rowspan='3'>"+sonuc+"</td><td></td>-<td>"+sonuc2+"</td></tr><tr><td>-</td><td>"+sonuc4+"</td></tr><tr><td>-</td><td>"+sonuc3+"</td></tr></table>"
  2469. return htmlrp
  2470. #return sonuc+"<br>"+sonuc2
  2471. '''borcdok=self.calistir(sql)
  2472. rapor=statikrapor()
  2473. dizibas=['cari kod','cari isim','vadesi geçen borc','toplam borc']
  2474. top_sutlar=[9,9,2,3]
  2475. rapor_html=rapor.diziYhtml(borcdok,dizibas,top_sutlar)
  2476. return rapor_html
  2477. '''
  2478. def kontrol_cari_hareket(self,merkez,tarih=""):
  2479. kaynak=merkez
  2480. #kaynak=self.sube_cariler(merkez)
  2481. #kaynak=self.diziYstr_dizi(str(kaynak))
  2482. simdiki_zaman=datetime.datetime.now()
  2483. if tarih=="":
  2484. tarih =simdiki_zaman
  2485. else:
  2486. tarih=self.tarih_format(tarih)
  2487. sql=open('./altyapi/sql/kontrol_cari_takip.sql','r').read()
  2488. sql=sql.replace('@kaynak@',str(kaynak))
  2489. sql=sql.replace('@vade_tarihi@',str(tarih))
  2490. #codecs.open('cari_borc_dokum_data.sql','w','iso-8859_9').write(sql)
  2491. rapor=statikrapor()
  2492. topsut=[]
  2493. rapor.sql(sql,rapbas="CARI KONTROLU",alt=1,topsut=topsut)
  2494. sonuc=rapor.getHtml()
  2495. htmlrp="<table><tr><td>"+sonuc+"</td><td>-</td><td>"+"r2"+"</td></tr></table>"
  2496. return htmlrp
  2497. def kontrol_cari_dokum(self,merkez,tarih=""):
  2498. kaynak=merkez
  2499. #kaynak=self.sube_cariler(merkez)
  2500. #kaynak=self.diziYstr_dizi(str(kaynak))
  2501. simdiki_zaman=datetime.datetime.now()
  2502. if tarih=="":
  2503. tarih =simdiki_zaman
  2504. else:
  2505. tarih=self.tarih_format(tarih)
  2506. sql=open('./altyapi/sql/kontrol_cari_borc_dokum.sql','r').read()
  2507. sql=sql.replace('@kaynak@',str(kaynak))
  2508. sql=sql.replace('@vade_tarihi@',str(tarih))
  2509. #codecs.open('cari_borc_dokum_data.sql','w','iso-8859_9').write(sql)
  2510. rapor=statikrapor()
  2511. topsut=[9,9,2,3]
  2512. rapor.sql(sql,rapbas="BORCLU CARI KONTROLU",alt=1,topsut=topsut)
  2513. sonuc=rapor.getHtml()
  2514. sql2=open('./altyapi/sql/kontrol_cari_alacak_dokum.sql','r').read()
  2515. sql2=sql2.replace('@kaynak@',str(kaynak))
  2516. sql2=sql2.replace('@vade_tarihi@',str(tarih))
  2517. #codecs.open('cari_alacak_dokum_data.sql','w','iso-8859_9').write(sql2)
  2518. rapor2=statikrapor()
  2519. topsut2=[9,9,2,3]
  2520. rapor2.sql(sql2,rapbas="ALACAK CARI KONTROLU",alt=1,topsut=topsut2)
  2521. sonuc2=rapor2.getHtml()
  2522. htmlrp="<table><tr><td>"+sonuc+"</td><td>-</td><td>"+sonuc2+"</td></tr></table>"
  2523. return htmlrp
  2524. def cari_odeme_plani(self,merkez,gun="60",raptip="dizi"):
  2525. cariler=[]
  2526. for row in self.cari_sorgu("rapor_kodu1","takip","dizi"):
  2527. cariler.append(row[0])
  2528. kaynak=merkez
  2529. data=""
  2530. plan=[]
  2531. for cari in cariler:
  2532. sql=open('./altyapi/sql/cari_odeme.sql','r').read()
  2533. sql=sql.replace('@carikod@',str(cari))
  2534. odeme=self.calistir(sql)[0][0]
  2535. if odeme:
  2536. odeme=float(str(odeme))
  2537. else:
  2538. odeme=0
  2539. sql=open('./altyapi/sql/cari_alacak.sql','r').read()
  2540. sql=sql.replace('@carikod@',str(cari))
  2541. alacaklar=self.calistir(sql)
  2542. kalan=0
  2543. if alacaklar:
  2544. for alacak in alacaklar:
  2545. borc=float(alacak[1])
  2546. if odeme>borc:
  2547. odeme=odeme-borc
  2548. else:
  2549. kalan=borc-odeme+kalan
  2550. odeme=0
  2551. tarih=str(alacak[0]).split()[0]
  2552. if kalan>0:
  2553. plan.append([self.cari(cari).isim,alacak[2],tarih,borc,kalan])
  2554. rapor=statikrapor()
  2555. dizibas=['isim','aciklama','vade_tarihi','vdtutar','tutar']
  2556. top_sutlar=[0,1]
  2557. rapor_html=rapor.diziYhtml(plan,dizibas,top_sutlar)
  2558. return rapor_html
  2559. def satis_raporu_kdvli(self,subekod,bastarih,sontarih):
  2560. bastarih=self.tarih_format(bastarih)
  2561. sontarih=self.tarih_format(sontarih)
  2562. sql=open('./altyapi/sql/kdvlisatistop.sql','r').read()
  2563. sql=sql.replace('@bastarih@',bastarih)
  2564. sql=sql.replace('@sontarih@',sontarih)
  2565. sql=sql.replace('@subekod@',subekod)
  2566. satislar=self.calistir(sql)
  2567. #codecs.open('kdvlisatis_data.sql','w','iso-8859_9').write(sql)
  2568. #print satislar[0],satislar[1]
  2569. gc_trh=satislar[0][3]
  2570. gctop=0
  2571. satisharlar=[]
  2572. satisharlar.append(["tarih",satislar[0][3]])
  2573. for satis in satislar:
  2574. if(satis[3]!=gc_trh):
  2575. #print "guntoplam",gctop
  2576. if len(satisharlar)>1:
  2577. satisharlar.append(["-","toplam satis",gctop])
  2578. satisharlar.append(["-","----------------------","-"])
  2579. #print self.tarih_turk(satis[3])
  2580. satisharlar.append(["tarih",satis[3]])
  2581. gc_trh=satis[3]
  2582. gctop=0
  2583. satisharlar.append([satis[0],satis[1],satis[2]])
  2584. gctop+=satis[2]
  2585. #print "guntoplam",gctop
  2586. satisharlar.append(["0","toplam satis",gctop])
  2587. rapor=statikrapor()
  2588. dizibas=['kodu','kdv grup ismi','tutar']
  2589. top_sutlar=[-1,-1,-1]
  2590. rapor_html=rapor.diziYhtml(satisharlar,dizibas,top_sutlar)
  2591. return rapor_html
  2592. def bakiye_tutar(self,subekod,tarih):
  2593. tarih=self.tarih_format(tarih)
  2594. sql=open('./altyapi/sql/tarihli_bakiye_tutar.sql','r').read()
  2595. sql=sql.replace('@bastarih@',tarih)
  2596. sql=sql.replace('@subekod@',subekod)
  2597. meblag=self.calistir(sql)[0][0]
  2598. if meblag:
  2599. return meblag
  2600. else:
  2601. return 0
  2602. def cari_alim_toplami(self,mkod,subekod,bastarih,sontarih):
  2603. bastarih=self.tarih_format(bastarih)
  2604. sontarih=self.tarih_format(sontarih)
  2605. sql=open('./altyapi/sql/cari_alim_toplami.sql','r').read()
  2606. sql=sql.replace('@bastarih@',bastarih)
  2607. sql=sql.replace('@sontarih@',sontarih)
  2608. sql=sql.replace('@subekod@',subekod)
  2609. sql=sql.replace('@mkod@',mkod)
  2610. meblag=self.calistir(sql)[0][0]
  2611. if meblag:
  2612. return meblag
  2613. else:
  2614. return 0
  2615. def cari_satis_toplami(self,subekod,bastarih,sontarih):
  2616. bastarih=self.tarih_format(bastarih)
  2617. sontarih=self.tarih_format(sontarih)
  2618. sql=open('./altyapi/sql/cari_satis_toplami.sql','r').read()
  2619. sql=sql.replace('@bastarih@',bastarih)
  2620. sql=sql.replace('@sontarih@',sontarih)
  2621. sql=sql.replace('@subekod@',subekod)
  2622. meblag=self.calistir(sql)[0][0]
  2623. if meblag:
  2624. return meblag
  2625. else:
  2626. return 0
  2627. def cari_satis_maliyet(self,subekod,bastarih,sontarih):
  2628. bastarih=self.tarih_format(bastarih)
  2629. sontarih=self.tarih_format(sontarih)
  2630. sql=open('./altyapi/sql/cari_satis_maliyeti.sql','r').read()
  2631. sql=sql.replace('@bastarih@',bastarih)
  2632. sql=sql.replace('@sontarih@',sontarih)
  2633. sql=sql.replace('@subekod@',subekod)
  2634. meblag=self.calistir(sql)[0][0]
  2635. if meblag:
  2636. return meblag
  2637. else:
  2638. return 0
  2639. def cari_iade_toplami(self,mkod,subekod,bastarih,sontarih):
  2640. bastarih=self.tarih_format(bastarih)
  2641. sontarih=self.tarih_format(sontarih)
  2642. sql=open('./altyapi/sql/cari_iade_toplami.sql','r').read()
  2643. sql=sql.replace('@bastarih@',bastarih)
  2644. sql=sql.replace('@sontarih@',sontarih)
  2645. sql=sql.replace('@subekod@',subekod)
  2646. sql=sql.replace('@mkod@',mkod)
  2647. meblag=self.calistir(sql)[0][0]
  2648. if meblag:
  2649. return meblag
  2650. else:
  2651. return 0
  2652. def pazar_rapor(self,mkod,subekod,bastarih,sontarih):
  2653. raporana=[]
  2654. devreden=self.bakiye_tutar(subekod,bastarih)
  2655. devredecek=self.bakiye_tutar(subekod,sontarih)
  2656. alimtop=self.cari_alim_toplami(mkod,subekod,bastarih,sontarih)
  2657. iadetop=self.cari_iade_toplami(mkod,subekod,bastarih,sontarih)
  2658. satistop=self.cari_satis_toplami(subekod,bastarih,sontarih)
  2659. stokaj=devreden-devredecek
  2660. #12:09 07.04.2015
  2661. #gat=alimtop+stokaj-iadetop
  2662. maliyet=self.cari_satis_maliyet(subekod,bastarih,sontarih)
  2663. #codecs.open('./sql_cikti/pazar_rapor_data.sql','w','iso-8859_9').write(sql)
  2664. raporana.append(['devreden',devreden])
  2665. raporana.append(['devredecek',devredecek])
  2666. raporana.append(['stokaj',stokaj])
  2667. raporana.append(['iade_toplami',iadetop])
  2668. raporana.append(['alim_toplami',alimtop])
  2669. raporana.append(['satilan_mal_maliyeti',maliyet])
  2670. raporana.append(['satilan_mal_tutari',satistop])
  2671. raporana.append(['kar_orani %',round(((satistop/maliyet)-1)*100,2)])
  2672. rapor=statikrapor()
  2673. dizibas=[self.cari(subekod).isim,bastarih+"-"+sontarih]
  2674. top_sutlar=[-1,-1,-1]
  2675. rapor_html=rapor.diziYhtml(raporana,dizibas,top_sutlar)
  2676. return rapor_html
  2677. def diziYstr_dizi(self,dizi):
  2678. diziler=dizi.split(',')
  2679. dizis=""
  2680. for cari in diziler:
  2681. dizis+=""+cari+","
  2682. dizis=""+dizis[1:len(dizis)-2]+""
  2683. return dizis
  2684. def sonalim_bf(self,kaynak,hedef,stokod):
  2685. sql=open('./altyapi/sql/sonalim_bf.sql','r').read()
  2686. sql=sql.replace('@hedef@',str(hedef))
  2687. sql=sql.replace('@kaynak@',str(kaynak))
  2688. sql=sql.replace('@stokod@',str(stokod))
  2689. bf=self.calistir(sql)
  2690. if bf:
  2691. bf=bf[0][0]
  2692. if(bf):
  2693. return round(float(bf),3)
  2694. return 0
  2695. def sonsatis_bf(self,kaynak,hedef,stokod):
  2696. sql=open('./altyapi/sql/sonsatis_bf.sql','r').read()
  2697. sql=sql.replace('@hedef@',str(hedef))
  2698. sql=sql.replace('@kaynak@',str(kaynak))
  2699. sql=sql.replace('@stokod@',str(stokod))
  2700. bf=self.calistir(sql)
  2701. if bf:
  2702. bf=bf[0][0]
  2703. if(bf):
  2704. return round(float(bf),3)
  2705. return 0
  2706. def stkYftr(self,stkno,kdvdurum='E',med='H',kaydeden="giom"):
  2707. ax=datetime.datetime.now()
  2708. print "mak.stkYftr islemi basladi...."
  2709. stknog=stkno
  2710. stkno=stkno.split('@')
  2711. otofisno=''
  2712. merkez=stkno[0]
  2713. if self.cari(merkez) is None:
  2714. return "hata merkez cari tanimsiz"
  2715. hedef=stkno[1]
  2716. hedef=stkno[1]
  2717. if self.cari(hedef) is None:
  2718. return "hata hedef cari tanimsiz"
  2719. urtkod=stkno[2]
  2720. fattip=stkno[3]
  2721. tarih=stkno[4].split('.')[0]
  2722. yil=tarih.split('-')[0]
  2723. ay=tarih.split('-')[1]
  2724. if(len(ay)==1):
  2725. ay='0'+ay
  2726. gun=tarih.split('-')[2]
  2727. if(len(gun)==1):
  2728. gun='0'+gun
  2729. randfis=randint(1000,9999)
  2730. tarih=gun+'-'+ay+'-'+yil
  2731. otofisno=fattip[0:2]+ay+gun+str(randfis)
  2732. yon=""
  2733. if(fattip in ("ALIS","AGIRIS","GIRIS","KGIRIS")):
  2734. yon="G"
  2735. if(fattip in ("SATIS","ACIKIS","DAT","CIKIS","KCIKIS")):
  2736. yon="C"
  2737. if(self.fisno_kontrol(otofisno)=="yok"):
  2738. fatura=Fatura()
  2739. fatura.islem='F'
  2740. fatura.fattip=yon
  2741. fatura.vadesay=1
  2742. fatura.tarih=tarih
  2743. fatura.vadetarih=tarih
  2744. fatura.fisno=otofisno
  2745. fatura.kaynak=merkez
  2746. fatura.hedef=hedef
  2747. fatura.med=med
  2748. fatura.irs='H'
  2749. fatura.kaydeden=kaydeden
  2750. fatura.stharlistno=stknog
  2751. fatura.kdvdurum=kdvdurum
  2752. fatura.takipkod=urtkod
  2753. fatura.aciklama=""
  2754. if(fattip in ["KCIKIS","KGIRIS"]):
  2755. fatura.islem='K'
  2756. fatura.kdvdurum='E'
  2757. tutarfsb=self.stk_fsb_al(stknog)
  2758. if tutarfsb is None:
  2759. return "olumsuz"
  2760. tutarsda=float(tutarfsb[0].split('=')[1])
  2761. if fattip=='KCIKIS':
  2762. tutarsda=tutarsda*-1
  2763. fatura.tutar=tutarsda
  2764. fatsonuc=self.faturalama(fatura,'y')
  2765. if fatsonuc != "olumsuz":
  2766. #faturalama olduktsan sonra silme
  2767. self.stk_sil(stknog)
  2768. ay=datetime.datetime.now()
  2769. print "mak.stkYftr bitti.",(ay-ax).total_seconds()
  2770. return "stk > fatura islemi basarili."
  2771. else:
  2772. return "stok kaynakli hata logu inceleyin"
  2773. else:
  2774. return "fisno uyumsuzluk sorunu"
  2775. def gtf_analiz(self,gtfdos):
  2776. with open(gtfdos,'r') as f:
  2777. gtop=0
  2778. ktop=0
  2779. vtop=0
  2780. for line in f:
  2781. sat=line
  2782. line=line.split()
  2783. islemtip=line[0]
  2784. #odemetip: 0 odeme 1 para ustu 2 doviz
  2785. odemetipi=sat[11:12]
  2786. #odemeref :0 nakit 0-39 1 kredi 2 veresiye
  2787. odemeref=sat[9:10]
  2788. #odeme iptali :0 iptal - 1 normal odendi
  2789. odemeiptal=sat[12:13]
  2790. if islemtip=='03' and odemetipi=='0':
  2791. tt=sat[13:19]
  2792. tt=tt.replace(',','.')
  2793. tutar=float(tt)
  2794. if odemeiptal=='0':
  2795. tutar=tutar*-1
  2796. #veresiye
  2797. if odemeref=='2':
  2798. vtop+=tutar
  2799. #kredi
  2800. if odemeref=='1':
  2801. ktop+=tutar
  2802. if(islemtip=='01'):
  2803. gecerli=line[7]
  2804. if(gecerli=='00'):
  2805. tutar=line[11]
  2806. tutar=tutar.replace(",",".")
  2807. tutar=float(tutar)
  2808. gtop+=tutar
  2809. ntop=round(gtop-(ktop+vtop),2)
  2810. ktop=round(ktop,2)
  2811. vtop=round(vtop,2)
  2812. return [ntop,ktop,vtop]
  2813. def kasabanka_rapor(self,merkez=""):
  2814. cariler=[]
  2815. caribankalar=self.cariler_getir("","B")
  2816. for cari in caribankalar:
  2817. kod=cari.split('@')[1]
  2818. cariler.append(kod)
  2819. carikasalar=self.cariler_getir("","K")
  2820. for cari in carikasalar:
  2821. kod=cari.split('@')[1]
  2822. cariler.append(kod)
  2823. raporana=""
  2824. for carix in cariler:
  2825. sql=open('./altyapi/sql/kasabanka_rapor.sql','r').read()
  2826. sql=sql.replace('@kaynak@',str(carix))
  2827. codecs.open('sql_cikti/kasabanka_rapor_data.sql','w','iso-8859_9').write(sql)
  2828. rapor=statikrapor()
  2829. topsut=[4,3,9,9,9,9,9]
  2830. rapor.sql(sql,alt=1,topsut=topsut)
  2831. raporana+=rapor.getHtml()+"<br>"
  2832. return raporana
  2833. def kasa_rapor(self,kasa,bastarih,sontarih,sonuc='html'):
  2834. sql=open('./altyapi/sql/kasa_rapor2.sql','r').read()
  2835. sql=sql.replace('@bastarih@',str(self.tarih_format(bastarih)))
  2836. sql=sql.replace('@sontarih@',str(self.tarih_format(sontarih)))
  2837. sql=sql.replace('@kaynak@',str(kasa))
  2838. open("kr2.sql",'w').write(sql)
  2839. if sonuc=='html':
  2840. rapor=statikrapor()
  2841. topsut=[4,3,9,9,9,9,9]
  2842. rapor.sql(sql,alt=1,topsut=topsut)
  2843. return rapor.getHtml()
  2844. else:
  2845. row=self.calistir(sql)
  2846. return row
  2847. def kasa_rapor_kir(self,kasa,bastarih,sontarih,sonuc='html'):
  2848. row=self.kasa_rapor(kasa,bastarih,sontarih,sonuc='dizi')
  2849. sqldosyak='./altyapi/sql/kasa_devir.sql'
  2850. sqlk=codecs.open(sqldosyak,'r','iso-8859_9').read()
  2851. sqlk=sqlk.replace('@kaynak@',kasa)
  2852. sqlk=sqlk.replace('@tarih@',str(self.tarih_format(bastarih)))
  2853. devir=self.calistir(sqlk)
  2854. devredecek=devir[0][0]
  2855. rapor=[]
  2856. rapor.append(["-----","-----","------","------","------",devredecek,"------"])
  2857. aratop=0
  2858. tarihgc=row[0][0]
  2859. for r in row:
  2860. tarih=r[0]
  2861. if tarih != tarihgc:
  2862. tarihgc=r[0]
  2863. rapor.append(["-----","-----","------","------","------","------","------"])
  2864. aratop=0
  2865. if r[3]==0:
  2866. aratop-=r[4]
  2867. else:
  2868. aratop+=r[3]
  2869. rapor.append([r[0],r[1],r[2],r[3],r[4],r[5]+devredecek,r[6]])
  2870. rapor.append(["-----","-----","------","------","------","------","------"])
  2871. if sonuc=='html':
  2872. dizibas=["tarih","cari","ack","giris","cikis","bakiye","r/gr"]
  2873. rapok=statikrapor()
  2874. return rapok.diziYhtml(rapor,dizibas,topsut=[-1,-1,-1,-1,-1,-1,-1])
  2875. else:
  2876. return rapor
  2877. def nesne_goster(self,nesne):
  2878. for attr, value in nesne.__dict__.iteritems():
  2879. print attr,value
  2880. def kullanicilar(self,sonuc='html'):
  2881. sql=open('./altyapi/sql/kullanicilar.sql','r').read()
  2882. if sonuc=='html':
  2883. rapor=statikrapor()
  2884. rapor.sql(sql,alt=1)
  2885. return rapor.getHtml()
  2886. else:
  2887. row=self.calistir(sql)
  2888. return row
  2889. def kullanici_getir(self,no):
  2890. sql=open('./altyapi/sql/kullanici_getir.sql','r').read()
  2891. sql=sql.replace('@no@',str(no))
  2892. row=self.calistir(sql)
  2893. dizi=self.dizi_dekod(row[0])
  2894. return dizi
  2895. def kullanici_getir2(self,no):
  2896. sql=open('./altyapi/sql/kullanici_getir.sql','r').read()
  2897. sql=sql.replace('@no@',str(no))
  2898. row=self.calistir(sql)
  2899. return row[0][2]
  2900. def kullanici_posta(self,no):
  2901. sql=open('./altyapi/sql/kullanici_getir.sql','r').read()
  2902. sql=sql.replace('@no@',str(no))
  2903. row=self.calistir(sql)
  2904. return row[0][3]
  2905. def kullanici_islem(self,kull,mod):
  2906. if(mod=='s'):
  2907. sql=open('./altyapi/sql/kullanici_sil.sql','r').read()
  2908. sql=sql.replace('@no@',str(kull.no))
  2909. if(mod=='g'):
  2910. sql=open('./altyapi/sql/kullanici_guncelle.sql','r').read()
  2911. sql=sql.replace('@no@',str(kull.no))
  2912. if(mod=='y'):
  2913. sql=open('./altyapi/sql/kullanici_ekle.sql','r').read()
  2914. if(mod in ['y','g']):
  2915. sql=sql.replace('@sifre@',str(kull.sifre))
  2916. sql=sql.replace('@eposta@',str(kull.eposta))
  2917. sql=sql.replace('@yetki@',str(kull.yetki))
  2918. sql=sql.replace('@uisim@',kull.uisim)
  2919. sql=sql.replace('@isim@',str(kull.isim))
  2920. if self.calis(sql)=="tamam":
  2921. return self.kullanicilar()
  2922. def giris_kontrol(self,isim,sifre):
  2923. sql=open('./altyapi/sql/giris_kontrol.sql','r').read()
  2924. sql=sql.replace('@isim@',str(isim))
  2925. sql=sql.replace('@sifre@',str(sifre))
  2926. row=self.calistir(sql)
  2927. if (row):
  2928. return row[0][0]
  2929. return None
  2930. def girdi_kontrol(self,id):
  2931. sql=open('./altyapi/sql/girdi_kontrol.sql','r').read()
  2932. sql=sql.replace('@id@',str(id))
  2933. row=self.calistir(sql)
  2934. if (row):
  2935. return row[0][0]
  2936. return None
  2937. def girdi_isim(self,id):
  2938. sql=open('./altyapi/sql/girdi_isim.sql','r').read()
  2939. sql=sql.replace('@id@',str(id))
  2940. row=self.calistir(sql)
  2941. if (row):
  2942. return row[0][0]
  2943. return None
  2944. def girdi_liste(self,sonuc='html'):
  2945. sql=open('./altyapi/sql/girdi_liste.sql','r').read()
  2946. if sonuc=='html':
  2947. rapor=statikrapor()
  2948. rapor.sql(sql,rapbas='bagli_kullanicilar',alt=1)
  2949. return rapor.getHtml()
  2950. else:
  2951. row=self.calistir(sql)
  2952. return row
  2953. def giris_ekle(self,id):
  2954. if self.girdi_kontrol(id) is None:
  2955. sql=open('./altyapi/sql/giris_ekle.sql','r').read()
  2956. sql=sql.replace('@id@',str(id))
  2957. return self.calis(sql)
  2958. def giris_sil(self,id):
  2959. sql=open('./altyapi/sql/giris_sil.sql','r').read()
  2960. sql=sql.replace('@id@',str(id))
  2961. return self.calis(sql)
  2962. def yetki_al(self,id):
  2963. sql=open('./altyapi/sql/yetki_al.sql','r').read()
  2964. sql=sql.replace('@id@',str(id))
  2965. row=self.calistir(sql)
  2966. if (row):
  2967. return row[0][0]
  2968. return None
  2969. #yapimasamasinda
  2970. def yetki_kontrol(self,oper,yetki):
  2971. sql=open('./altyapi/sql/yetki_kontrol.sql','r').read()
  2972. sql=sql.replace('@id@',str(id))
  2973. row=self.calistir(sql)
  2974. if (row):
  2975. return row[0][0]
  2976. return None
  2977. def ayar_islem(self,ayar,mod):
  2978. if(mod=='s'):
  2979. sql=open('./altyapi/sql/ayar_sil.sql','r').read()
  2980. sql=sql.replace('@no@',str(ayar.no))
  2981. if(mod=='g'):
  2982. sql=open('./altyapi/sql/ayar_guncelle.sql','r').read()
  2983. sql=sql.replace('@no@',str(ayar.no))
  2984. if(mod=='y'):
  2985. sql=open('./altyapi/sql/ayar_ekle.sql','r').read()
  2986. if(mod in ['y','g']):
  2987. sql=sql.replace('@ayar_kulno@',str(ayar.kulno))
  2988. sql=sql.replace('@ayar_bas@',str(ayar.bas))
  2989. sql=sql.replace('@ayar_deger@',ayar.deger.encode('iso-8859_9'))
  2990. if self.calis(sql)=="tamam":
  2991. return self.ayar_liste()
  2992. def ayar_liste(self,sonuc='html'):
  2993. sql=open('./altyapi/sql/ayar_liste.sql','r').read()
  2994. if sonuc=='html':
  2995. rapor=statikrapor()
  2996. rapor.sql(sql,rapbas='ayarlar',alt=1)
  2997. return rapor.getHtml()
  2998. else:
  2999. row=self.calistir(sql)
  3000. return row
  3001. def ayar_getir(self,no):
  3002. sql=open('./altyapi/sql/ayar_getir.sql','r').read()
  3003. sql=sql.replace('@no@',str(no))
  3004. row=self.calistir(sql)
  3005. degerler=[]
  3006. if row:
  3007. vt_degerler=row[0]
  3008. for vtd in vt_degerler:
  3009. degerler.append(vtd)
  3010. return degerler
  3011. #row[0][3]=vt_degerler
  3012. def ayar_al(self,kul_no,ayar_bas):
  3013. sql=open('./altyapi/sql/ayar_al.sql','r').read()
  3014. sql=sql.replace('@kul_no@',str(kul_no))
  3015. sql=sql.replace('@ayar_bas@',str(ayar_bas))
  3016. row=self.calistir(sql)
  3017. if row:
  3018. ayar_deger=row[0][0]
  3019. if '#' in ayar_deger:
  3020. ayar_deger=ayar_deger.split('#')
  3021. degerler=[]
  3022. for ayar in ayar_deger:
  3023. degerler.append(ayar)
  3024. return degerler
  3025. return ayar_deger
  3026. else:
  3027. return None
  3028. def vt_yedekle(self,vt_isim):
  3029. now=str(datetime.datetime.now()).split()[0]
  3030. os.system("mysqldump -u root -pmysql_1234 "+vt_isim+" > /opt/yedekler/giom_dbyedek/"+vt_isim+"_yedek_"+str(now)+".sql")
  3031. os.system("mysqldump -u root -pmysql_1234 "+vt_isim+" > /opt/yedekler2/"+vt_isim+"_yedek_"+str(now)+".sql")
  3032. return "kontrol ediniz"
  3033. def vt_yukle(self,yedek_isim):
  3034. os.system("mysql -u root -pmysql_1234 giomvt < giomvtyedek.sql")
  3035. #gunzip -c test.sql.gz | mysql -u root -pmysql_1234 giomvt
  3036. return "kontrol ediniz"
  3037. def stkYxls2(self,stkno):
  3038. #stkod,stkad,miktar,bf,tutar,stoklistno
  3039. wb = xlwt.Workbook(encoding='latin-1')
  3040. ws = wb.add_sheet(stkno)
  3041. satir=1
  3042. sutunlar=[0,1,2]
  3043. basliklar=["isim","miktar","barkod"]
  3044. harlist=self.stk_al(stkno)
  3045. for sutun in sutunlar:
  3046. data=basliklar[sutun]
  3047. ws.write(satir-1,sutun,data)
  3048. for kayit in harlist:
  3049. for sutun in sutunlar:
  3050. data=kayit[sutun+2]
  3051. print data,satir,sutun
  3052. if sutun==0:
  3053. ws.write(satir,sutun,data)
  3054. ws.col(sutun).width = 0x3600
  3055. if sutun==2:
  3056. ws.write(satir,sutun,self.stok(kayit[1]).barkod6)
  3057. ws.col(sutun).width = 0x0f00
  3058. if sutun==1:
  3059. ws.write(satir,sutun,data)
  3060. satir+=1
  3061. wb.save('./stkYxls/stk_'+stkno+'.xls')
  3062. def stkYxls(self,stknolar,dosya):
  3063. #stkod,stkad,miktar,bf,tutar,stoklistno
  3064. wb = xlwt.Workbook(encoding='latin-1')
  3065. ws = wb.add_sheet("stklar")
  3066. satir=1
  3067. sutunlar=[0,1,2,3]
  3068. basliklar=["isim","miktar","bf","tutar"]
  3069. stklar=[]
  3070. for stkno in stknolar:
  3071. harlist=self.stk_al(stkno)
  3072. stklar.append(["-","-","-","-","toplam",""])
  3073. stklar.append(["","",stkno,"-","-","-"])
  3074. for har in harlist:
  3075. #print har
  3076. #stklar.append([har[2],har[3],har[4],har[5]])
  3077. stklar.append(har)
  3078. for sutun in sutunlar:
  3079. data=basliklar[sutun]
  3080. ws.write(satir-1,sutun,data)
  3081. for kayit in stklar:
  3082. print kayit
  3083. for sutun in sutunlar:
  3084. data=kayit[sutun+2]
  3085. #print data,satir,sutun
  3086. if sutun==0:
  3087. ws.write(satir,sutun,data)
  3088. ws.col(sutun).width = 0x3600
  3089. else :
  3090. ws.write(satir,sutun,data)
  3091. satir+=1
  3092. wb.save('./stkYxls/'+dosya+'.xls')
  3093. def terazi_data(self):
  3094. sql=open('./altyapi/sql/terazi_data.sql','r').read()
  3095. row=self.calistir(sql)
  3096. return row
  3097. def teraziYxls(self):
  3098. #stkod,stkad,miktar,bf,tutar,stoklistno
  3099. wb = xlwt.Workbook(encoding='latin-1')
  3100. ws = wb.add_sheet("PLU")
  3101. satir=1
  3102. basliklar="abcdefghijklmnoprstuvwqyzABCDEFGHIKLMNOPRSTUVYZQWX"
  3103. for sutun in range(50):
  3104. data=basliklar[sutun]
  3105. ws.write(satir-1,sutun,data)
  3106. kayitlar=self.terazi_data()
  3107. for kayit in kayitlar:
  3108. for sutun in range(50):
  3109. #print kayit,satir,sutun
  3110. if sutun==0 or sutun==2:
  3111. ws.write(satir,sutun,"1")
  3112. if sutun==1 or sutun==3:
  3113. #barkod
  3114. ws.write(satir,sutun,kayit[0])
  3115. if sutun==4:
  3116. #isim
  3117. ws.write(satir,sutun,kayit[1])
  3118. ws.col(sutun).width = 0x3000
  3119. if sutun==17:
  3120. #bf
  3121. ws.write(satir,sutun,float(kayit[2])*100)
  3122. if sutun in [5,6,13,19,21,22,23,25,26,28,31] or sutun>32:
  3123. ws.write(satir,sutun,"")
  3124. if sutun in [7,8,9,10,11,12,14,15,16,18,20,24,27,29,30,32]:
  3125. ws.write(satir,sutun,"0")
  3126. satir+=1
  3127. wb.save('terazi_data.xls')
  3128. def entegre(self):
  3129. sql=open('./altyapi/sql/entegre.sql','r').read()
  3130. #sql=sql.replace('@kul_no@',str(kul_no))
  3131. #sql=sql.replace('@ayar_bas@',str(ayar_bas))
  3132. row=self.calistir(sql)
  3133. entegre=[]
  3134. for ro in row:
  3135. tarih=self.tarih_turk(str(ro[0]))
  3136. fno=ro[1]
  3137. isim=ro[2]
  3138. vno=ro[3]
  3139. tip=ro[10]
  3140. kdv0=0
  3141. mat1=ro[4]
  3142. mat1=float(mat1)
  3143. if mat1!=0:
  3144. kdv0=1
  3145. oran=1
  3146. kdv1=ro[5]
  3147. kdv1=float(kdv1)
  3148. entegre.append([tarih,fno,isim,vno,oran,mat1,kdv1,mat1+kdv1,tip])
  3149. mat8=ro[6]
  3150. mat8=float(mat8)
  3151. if mat8!=0:
  3152. kdv0=1
  3153. oran=8
  3154. kdv8=ro[7]
  3155. kdv8=float(kdv8)
  3156. entegre.append([tarih,fno,isim,vno,oran,mat8,kdv8,mat8+kdv8,tip])
  3157. mat18=ro[8]
  3158. mat18=float(mat18)
  3159. if mat18!=0:
  3160. kdv0=1
  3161. oran=18
  3162. kdv18=ro[9]
  3163. kdv18=float(kdv18)
  3164. entegre.append([tarih,fno,isim,vno,oran,mat18,kdv18,mat18+kdv18,tip])
  3165. if kdv0==0:
  3166. oran=0
  3167. mat0=ro[11]
  3168. mat0=float(mat0)
  3169. entegre.append([tarih,fno,isim,vno,oran,mat0,0,mat0,tip])
  3170. wb = xlwt.Workbook(encoding='latin-1')
  3171. ws = wb.add_sheet('entegre')
  3172. satir=1
  3173. sutunlar=[0,1,2,3,4,5,6,7,8]
  3174. basliklar=["tarih","fatura no","cari isim","vergi numarasi","kdv orani","kdv matrah","kdvtop","kalem tutar","tip"]
  3175. for sutun in sutunlar:
  3176. data=basliklar[sutun]
  3177. ws.write(satir-1,sutun,data)
  3178. for kayit in entegre:
  3179. for sutun in sutunlar:
  3180. data=kayit[sutun]
  3181. #print data
  3182. if sutun==2:
  3183. ws.write(satir,sutun,data)
  3184. else:
  3185. ws.write(satir,sutun,data)
  3186. ws.col(sutun).width = 0x0f00
  3187. if sutun==2:
  3188. ws.col(sutun).width = 0x3600
  3189. satir+=1
  3190. wb.save('entegre_giom.xls')
  3191. print "entegresyon tamam.->entegre_giom.xls"
  3192. '''rapor=statikrapor()
  3193. basliklar=["tarih","fatura no","cari isim","vergi numarasi","kdv orani","kdv matrah","kdvtop","kalem tutar","tip"]
  3194. top_sutlar=[0,1]
  3195. rapor_html=rapor.diziYhtml(entegre,basliklar,top_sutlar)
  3196. return rapor_html'''
  3197. def dizi_dekod(self,dizi):
  3198. dekod=[]
  3199. for d in dizi:
  3200. yd=d
  3201. if isinstance(d, str):
  3202. yd=d
  3203. dekod.append(yd)
  3204. return dekod
  3205. def etk_basim_kaydet(self,kod,bf):
  3206. sqldosya='./altyapi/sql/etk_basim_kaydet.sql'
  3207. sql=open(sqldosya,'r').read()
  3208. sql=sql.replace('@kod@',str(kod))
  3209. sql=sql.replace('@bf@',str(bf))
  3210. sonuc=self.calis(sql)
  3211. return sonuc
  3212. def etk_basim_kontrol(self,kod,bf):
  3213. bf=str(bf).replace(',','.')
  3214. sqldosya='./altyapi/sql/etk_basim_kontrol.sql'
  3215. sql=open(sqldosya,'r').read()
  3216. sql=sql.replace('@kod@',str(kod))
  3217. sql=sql.replace('@bf@',str(bf))
  3218. sonuc=self.calistir(sql)
  3219. if sonuc:
  3220. return str(sonuc[0][0])
  3221. else:
  3222. return "yok"
  3223. def bakim1(self,bakim,sonuc='html'):
  3224. sql=""
  3225. bakim=str(bakim)
  3226. if bakim=="1":
  3227. sql=open('./altyapi/sql/cift_inckey_tespit.sql','r').read()
  3228. if bakim=="2":
  3229. sql=open('./altyapi/sql/kontrol_tarih_uyumsuz.sql','r').read()
  3230. if bakim=="3":
  3231. sql=open('./altyapi/sql/tutar_toplam_uyumsuzlugu.sql','r').read()
  3232. if sonuc=='html':
  3233. rapor=statikrapor()
  3234. rapor.sql(sql,rapbas='ayarlar',alt=1)
  3235. return rapor.getHtml()
  3236. else:
  3237. row=self.calistir(sql)
  3238. return row
  3239. def stk_shsifirlama(self,stkno,merkezkod,carikod,caribag=""):
  3240. con = lite.connect("stoklist.db")
  3241. sqldosya='./altyapi/sql/sube_giren_mallar.sql'
  3242. sql=open(sqldosya,'r').read()
  3243. sql=sql.replace('@carikod@',str(carikod))
  3244. sql=sql.replace('@merkezkod@',str(merkezkod))
  3245. sonuc=self.calistir(sql)
  3246. maltum=[]
  3247. for son in sonuc:
  3248. maltum.append(son)
  3249. stkhar=self.stk_al(stkno)
  3250. stkodlar=[]
  3251. for kod in stkhar:
  3252. stkodlar.append(kod[1])
  3253. with con:
  3254. cur = con.cursor()
  3255. for mal in maltum:
  3256. stkod=mal[0]
  3257. if stkod not in stkodlar:
  3258. stkad=mal[1]
  3259. if caribag=="":
  3260. bf=self.stok(stkod).satis_fiat1
  3261. else:
  3262. bf=self.sonsatis_bf(carikod,caribag,stkod)
  3263. stharek=(stkod,stkad,float(0),float(bf),float(0),stkno)
  3264. cur.execute("INSERT INTO stoklist (stkod,stkad,miktar,bf,tutar,stoklistno) VALUES(?, ?,?, ?, ?,?)", stharek)
  3265. con.close()
  3266. return "tm"