#-*- coding: utf-8 -*-
#import wxversion
#wxversion.select('2.8')

import wx
import os
import re
import json
import sys
import string
import sqlite3
import datetime
#import psycopg2
import wx.grid as gridlib
import wx.lib.masked as masked
import Printer as PRx
import HandyUtilities as HU
import Common_Dialogs as CDialog
from decimal import Decimal, ROUND_HALF_UP, ROUND_UP, ROUND_05UP





class FillIn(object):
    def __init__(self,gridname,debug=True):
        self.grid = wx.FindWindowByName(gridname)
        HU.BeVerbose('Fill In ...')
    
    
    def POSCustAcctGrid(self,custNum=None,debug=True):
        HU.BeVerbose('... POS Cust Acct Grid')
        grid = self.grid
        acctInfo = HU.SetAcctInfo(grid.GetName())
        if custNum is None:
            set_list = [('Account Number','PLACEHOLDER')]
            #grid.SetCellValue(0,0,'PLACEHOLDER')
            HU.FillGrid(grid.GetName(),set_list, col=0)
                
            return
                    
        fields = '''cust_num, first_name, last_name,
                    address_acct_num, phone_numbers'''
        returnd = HU.LookupDB('customer_basic_info').Mode2(custNum,'cust_num',fields)
                                            
        HU.Debugger(returnd,True)
        (cust_numd,first_named, last_named, address_acct_numd,phoned_JSON) = returnd
                
        fields = '''street_num, street_direction, street_name,
                    street_type,unit,city,zipcode,state,address2'''
        returnd = HU.LookupDB('address_accounts').Mode2(address_acct_numd,'addr_acct_num',fields)
        HU.Debugger('Returnd : {} = {}'.format(returnd, len(returnd)),debug)
                
        (street_numd,street_directiond,street_named,street_typed, unitd,cityd,zipcoded,stated,addressed2) = returnd
        
        print('flname : {} {}'.format(first_named, last_named))
        
        acctInfo.custAcctNum(cust_numd)
        
        acctInfo.name(first_named, last_named)