# Create / Update Receipt Data from ASN Interface Files

import os
import time
import datetime
import json
import mysql.connector
import datetime
from fpdf import FPDF
# from xlrd import open_workbook

import default_setting

class PDF(FPDF):
# Page header
	def header(self):
# Logo
		self.image('../../../images/vel_logo_large.jpg',10,6,50)
# Arial bold 15
		self.set_font('Arial','B',15)
# Move to the right
		self.cell(100)
# Title
		self.cell(50,10,'Pick Sheet',0,0,'C')
# Line break
		self.ln(20)

# Page footer
	def footer(self):
# Position at 1.5 cm from bottom
		self.set_y(-15)
# Arial italic 8
		self.set_font('Arial','I',8)
# date / time
#		date = date('d/m/Y h:i:s a', time())
		date = getts()
# Page number
		self.cell(0,10,'Page '+str(self.page_no())+'   Date '+str(date),0,0,'C')
		
# Get Current Path
dir_path = os.path.dirname(os.path.realpath(__file__))

def getts():
	ts = time.time()
	ts = datetime.datetime.fromtimestamp(ts).strftime('_%Y%m%d_%H%M%S')
	return ts

# Barcode table
def barcodetablepdf(pdf, header, data, customerref):
# date / time
		date = getts()
# barcode settings
		fontSize = 8
		marge    = 5   # between barcode and hri in pixel
		x        = 30  # barcode center
		y        = 70  # barcode center
		height   = 10  # barcode height in 1D ; module size in 2D
		width    = 0.25 # barcode width in 1D ; not use in 2D
		angle    = 0   # rotation in degrees  
		code     = 'VANTEC' # barcode text;)
		type     = 'code39'
		black    = '000000'; # color in hex
# Headings
		pdf.text(10,50,"Report Date: "+str(date))
		
		pdf.set_font('Arial','',fontSize)
		pdf.set_text_color(0, 0, 0)
# Initial Line
		pdf.ln(30)
# Customer Ref.
		x = 100
		pdf.set_font('Arial','',15)
		pdf.text(x, y, customerref)
#		barcode = pdf.barcode::fpdf(this, black, x+50, y, angle, type,customerref, width, height);
		pdf.code39(customerref, x+50, y, width, height)

def pickPrint(cnx):
#	data = LoadData(cnx)
	
	pdf = PDF()
	pdf.add_page()
# Column headings
	header = "Pick Sheet"
	pdf.set_font('Arial','',12)
	data = ''
	barcodetablepdf(pdf,header,data,'TEST')
	pdf.ln(5)
	output = "f"
	if (output == ""):
		pdf.output()
	elif(output == "f"):
		mPdf = os.path.join(dir_path, '../../../vimsreports/picksheet.pdf')
		pdf.output(mPdf,output)
	else:
		mPdf = "../../../vimsreports_arcv/picksheet.pdf"
		pdf.output(mPdf,'')
	return "OK  -picksheetPdf"
			
def main():
	ts = getts()
	print('Time:'+str(ts))
# Default Connection / System Settings
	defaults = default_setting.defaultSettings()
# mySql Connector
	cnx = mysql.connector.connect(user=defaults['dbuser'], password=defaults['dbpwd'],host=defaults['dbhost'],database=defaults['dbase'])
# Generate Pick Sheet
	pickPrint(cnx)
		
if __name__ == '__main__':
	main()