#!perl use strict; use lib '.'; use DBI; use NightsBridge; my $database = $ARGV[0]||'wcfvm_1'; # a : signal = 1. will pull clients from Nightbridage and add to local POS. # b : signal = 0 . POS admin need to setup room id and account id for each client - do manaully. my $signal = $ARGV[1]||'';#singal for pulling Nighebridge clients ## my $nightsbridge_username; my $nightsbridge_password; my $nightsbridge_bbid; my $nightsbridge_bbid_pass; my $nightsbridge_accountId; my $nightsbridge_roomId; # get configurations from database spaceusers:settings # site link: extranet/profiles/index.cgi?action=generic =pre Table : set sql_mode=""; DROP TABLE nightbridge_invoice; CREATE TABLE nightbridge_invoice( id int(10) unsigned NOT NULL AUTO_INCREMENT, invoice varchar(50) not null default '', client int(10) not null default 0, created datetime , status tinyint not null default 0, primary key `id`(`id`), key `created`(`created`) ); set sql_mode=""; ALTER TABLE tillclients ADD nightsaccountId int(10); ALTER TABLE tillclients ADD nightsroomId int(10); ALTER TABLE tillclients ADD nights_fullname varchar(50) not null default ''; ALTER TABLE tillclients ADD nights_clientid varchar(30) not null default ''; ALTER TABLE tillclients ADD nights_firstname varchar(30) not null default ''; ALTER TABLE tillclients ADD nights_surename varchar(30) not null default ''; ALTER TABLE tillclients ADD KEY `nights_clientid`(`nights_clientid`); CREATE TABLE nightbridge_guests( id int(10) unsigned NOT NULL AUTO_INCREMENT, clients text, created datetime not null default '000-00-00 00:00:00', primary key (`id`) ); INSERT INTO nightbridge_guests SET clients='',created=NOW(); 21697 omfrcj spacesolutions-pos 963430df0a2775d4 =cut my $dbh = DBI->connect("DBI:mysql:spaceusers;host=127.0.0.1",'root','fbg4ips') or die $DBI::errstr; my $settings = $dbh->selectall_arrayref("SELECT * FROM settings WHERE db=?",{ Slice=>{} },$database); foreach(@$settings){ $nightsbridge_username = $_->{val} if $_->{name} eq 'nightsbridge_username'; $nightsbridge_password = $_->{val} if $_->{name} eq 'nightsbridge_password'; $nightsbridge_bbid = $_->{val} if $_->{name} eq 'nightsbridge_bbid'; $nightsbridge_bbid_pass = $_->{val} if $_->{name} eq 'nightsbridge_bbid_pass'; $nightsbridge_accountId = $_->{val} if $_->{name} eq 'nightsbridge_accountId'; $nightsbridge_roomId = $_->{val} if $_->{name} eq 'nightsbridge_roomId'; } $dbh->disconnect; $dbh = DBI->connect("DBI:mysql:$database;host=127.0.0.1",'root','fbg4ips') or die $DBI::errstr; NightsBridge::getHouse({ dbh => $dbh, nightsbridge_username => $nightsbridge_username, nightsbridge_password => $nightsbridge_password, nightsbridge_bbid => $nightsbridge_bbid, nightsbridge_bbid_pass=> $nightsbridge_bbid_pass, nightsbridge_accountId=> $nightsbridge_accountId, nightsbridge_roomId => $nightsbridge_roomId, }) if $signal; #exit; ##TEST my $res = $dbh->selectall_arrayref("SELECT * FROM nightbridge_invoice WHERE status=0 ORDER BY created",{ Slice=>{} }); foreach my $night(@$res){ print "Sending Invoice:$night->{invoice}\n"; my $tillinvoice = $dbh->selectrow_arrayref("SELECT account FROM tillinvoices WHERE id=? LIMIT 1",undef,$night->{invoice}); if($tillinvoice->[0] > 0){ #account my $ret_ok = NightsBridge::postExtras({ dbh => $dbh, invoice => $night->{invoice}, client => $night->{client}, nightsbridge_username => $nightsbridge_username, nightsbridge_password => $nightsbridge_password, nightsbridge_bbid => $nightsbridge_bbid, nightsbridge_bbid_pass=> $nightsbridge_bbid_pass, nightsbridge_accountId=> $nightsbridge_accountId, nightsbridge_roomId => $nightsbridge_roomId, invoice_account => $tillinvoice->[0], }); $dbh->do("UPDATE nightbridge_invoice SET status=1 WHERE id=?",undef,$night->{id}) if $ret_ok=~/OK/; print $ret_ok,"\n"; } } print "Done\n";