3 ######################################################################
4 # This module is compatible only with SQL-Ledger version 2.6.x.
5 # Copy it to your SQL-Ledger installation directory as ws_server.pl.
6 ######################################################################
8 use Frontier
::Responder
;
11 ######################################################################
12 # IMPORTANT - modify this to point to your SQL-Ledger installation!
13 ######################################################################
14 use lib qw
(/var/www
/sql
-ledger
);
24 require "sql-ledger.conf";
26 my $add_customer = \
&rpc_add_customer
;
27 my $add_salesman = \
&rpc_add_employee
;
28 my $add_invoice = \
&rpc_add_invoice
;
29 my $customer_balance = \
&rpc_customer_balance
;
31 my $res = Frontier
::Responder
->new( methods
=> {
32 'ezybiz.add_invoice' => $add_invoice,
33 'ezybiz.add_salesman' => $add_salesman,
34 'ezybiz.customer_balance' =>$customer_balance,
35 'ezybiz.add_customer' => $add_customer
40 sub rpc_customer_balance
{
42 if ($$post_hash{id
} > 0 ) {
43 my $myconfig = new User
"$memberfile", "$oemr_username";
44 $myconfig->{dbpasswd
} = unpack 'u', $myconfig->{dbpasswd
};
46 $form->{title
} = "AR Outstanding";
47 $form->{outstanding
} = "1";
48 $form->{customer_id
} = $$post_hash{id
};
49 $form->{sort} = "transdate" ;
51 $form->{nextsub
} = "transaction";
52 $form->{vc
} = "customer" ;
53 $form->{action
} = 'Continue';
55 AA
::transactions
("",\
%$myconfig, \
%$form);
57 my ($paid,$amount) = 0;
59 # Exclude invoices that are not yet due (i.e. waiting for insurance).
62 my $today = sprintf("%04u-%02u-%02u", $now[5] + 1900, $now[4] + 1, $now[3]);
63 foreach my $resref (@
{$$form{transactions
}}) {
64 my $duedate = substr($$resref{duedate
}, 6) . "-" . substr($$resref{duedate
}, 0, 5);
65 if ($duedate le $today) {
66 $paid += $$resref{paid
};
67 $amount += $$resref{amount
};
71 my $retval = $amount - $paid;
78 use lib
'/usr/lib/perl5/site_perl/5.8.3';
82 #take struct of data and map to post data to create the customer, return the id
83 my $myconfig = new User
"$memberfile", "$oemr_username";
84 $myconfig->{dbpasswd
} = unpack 'u', $myconfig->{dbpasswd
};
86 $form->{name
} = substr($$post_hash{'firstname'} . " " . $$post_hash{'lastname'}, 0, 64);
87 $form->{discount
} = "";
89 $form->{taxincluded
} = "1";
90 $form->{creditlimit
} = "0";
91 $form->{id
} = $$post_hash{'foreign_id'};
93 $form->{employee
} = "";
94 $form->{pricegroup
} = "";
95 $form->{business
} = "";
96 $form->{language
} = "";
97 $form->{address1
} = substr($$post_hash{'address'}, 0, 32);
98 $form->{address2
} = substr($$post_hash{'address'}, 32, 32);
99 $form->{city
} = substr($$post_hash{'suburb'}, 0, 32);
101 if($$post_hash{'state'}){
102 $form->{state} = substr($$post_hash{'state'}, 0, 32);
104 $form->{state} = substr($$post_hash{'geo_zone_id'}, 0, 32);
106 $form->{zipcode
} = substr($$post_hash{'postcode'}, 0, 10);
107 $form->{country
} = "";
108 $form->{contact
} = "";
109 $form->{phone
} = substr($$post_hash{'phone1'}, 0, 20);
111 $form->{email
} = $$post_hash{'email'};
112 $form->{taxnumber
} = substr($$post_hash{'ssn'}, 0, 32);
113 $form->{curr
} = "USD";
114 $form->{customernumber
} = $$post_hash{'customernumber'};
115 @t = localtime(time);
120 $form->{startdate
} = "$mm-$dd-$yy";
122 CT
::save_customer
('', \
%$myconfig, \
%$form);
123 my $retVal = $form->{id
};
130 my ($post_hash) = @_;
131 my $myconfig = new User
"$memberfile", "$oemr_username";
132 $myconfig->{dbpasswd
} = unpack 'u', $myconfig->{dbpasswd
};
134 $form->{id
} = $$post_hash{'foreign_id'};
135 $form->{name
} = $$post_hash{'fname'} . " " . $$post_hash{'lname'};
136 $form->{sales
} = $$post_hash{'authorized'};
137 @t = localtime(time);
142 $form->{startdate
} = "$mm-$dd-$yy";
143 HR
::save_employee
("",\
%$myconfig, \
%$form);
144 my $retVal = $form->{id
};
150 my ($post_hash) = @_;
152 my $myconfig = new User
"$memberfile", "$oemr_username";
153 $myconfig->{dbpasswd
} = unpack 'u', $myconfig->{dbpasswd
};
156 $form->{employee
} = "--" . $$post_hash{'salesman'};
157 $form->{customer_id
} = $$post_hash{'customerid'};
158 $form->{invnumber
} = $$post_hash{'invoicenumber'};
159 $form->{amount
} = $$post_hash{'total'};
160 $form->{netamount
} = $$post_hash{'total'};
161 $form->{notes
} = $$post_hash{'notes'};
162 $form->{department
} = "";
163 $form->{currency
} = "USD";
164 $form->{defaultcurrency
} = "USD";
166 # This is the AR account number, needed by IS::post_invoice.
167 $form->{AR
} = $oemr_ar_acc;
169 # This will use the posting date as the billing date
170 @t = localtime(time);
175 $form->{transdate
} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900);
178 #Uncoment this following line if you rather use the DOS as the billing date.
180 # $form->{transdate} = $$post_hash{'dosdate'};
183 # If there is insurance, set a future due date so we don't bother
184 # the patient for a while.
186 if ($$post_hash{'payer_id'}) {
187 @t = localtime(60 * 60 * 24 * $oemr_due_days + time);
188 $form->{duedate
} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900);
190 $form->{duedate
} = $form->{transdate
};
193 # Get out if the invoice already exists.
195 my $dbh = $form->dbconnect($myconfig);
196 my $query = qq|SELECT id FROM ar WHERE invnumber
= ?
|;
197 my $eth = $dbh->prepare($query) || die "Failed to prepare ar query";
198 $eth->execute($$post_hash{'invoicenumber'}) || die "Failed to execute ar query";
199 ($trans_id) = $eth->fetchrow_array;
203 print STDERR
"Skipping invoice $trans_id = " . $$post_hash{'invoicenumber'} . "\n";
208 #loop through line items and add them to invoice
210 my $j = 1; #this is for copays should only be one but who knows -j
212 my $items = $$post_hash{'items'};
214 foreach my $line_item (@
$items)
216 if($$line_item{'itemtext'} =~ /COPAY/){
217 $form->{"datepaid_$j"} = "$mm-$dd-$yy";
218 $form->{"source_$j"} = "Co-pay";
219 $form->{"memo_$j"} ='Co-pay';
220 $form->{"paid_$j"} = abs($$line_item{'price'});
221 $form->{"AR_paid_$j"} = "$oemr_cash_acc" . "--";
227 my $query = qq|SELECT id FROM chart WHERE accno
= ?
|;
228 my $eth = $dbh->prepare($query) || die "Failed to prepare chart query";
229 $eth->execute($$line_item{'glaccountid'}) || die "Failed to execute chart query";
230 ($chart_id) = $eth->fetchrow_array;
233 $form->{"qty_$i"} = $$line_item{'qty'};
234 $form->{"discount_$i"} = 0;
235 $form->{"sellprice_$i"} = $$line_item{'price'};
237 $form->{taxincluded
} = 1;
238 $form->{"taxaccounts_$i"} = 0;
239 $form->{"income_accno_$i"} = $$line_item{'glaccountid'};
240 $form->{"income_accno_id_$i"} = $chart_id;
242 $form->{"id_$i"} = add_goodsandservices
(\
%$myconfig, \
%$form, $oemr_services_partnumber,
243 'Medical Services', '');
245 $form->{"description_$i"} = $$line_item{'itemtext'};
246 $form->{"unit_$i"} = '';
247 $form->{"serialnumber_$i"} = $$line_item{'maincode'};
249 # Save the insurance company ID as the SL project ID. This gives us a way
250 # to associate each invoice item with its insurance payer. The clinic will
251 # probably want to write some reporting software taking advantage of this.
253 $form->{"projectnumber_$i"} = "--" . $$post_hash{'payer_id'}
254 if ($$post_hash{'payer_id'});
261 $form->{paidaccounts
} = $j - 1;
262 $form->{rowcount
} = $i - 1;
263 IS
::post_invoice
("", \
%$myconfig, \
%$form);
264 my $retVal = $form->{id
};
270 my ($myconfig, $form, $number) = @_;
272 # connect to database
273 my $dbh = $form->dbconnect($myconfig);
275 my $query = qq|SELECT id FROM parts WHERE partnumber
= ?
|;
276 my $eth = $dbh->prepare($query) || die "Failed to create select id from parts query";
277 $eth->execute($number) || die "Failed to execute select id from parts query";
278 ($retval) = $eth->fetchrow_array;
284 sub add_goodsandservices
286 my ($myconfig, $form, $code, $desc, $price) = @_;
288 $retval = get_partid
($myconfig, $form, $code);
292 # connect to database, turn off autocommit
293 my $dbh = $form->dbconnect_noauto($myconfig);
294 my $query = qq|insert into parts
(partnumber
,description
,listprice
,sellprice
) values(?
,?
,?
,?
)|;
295 my $eth = $dbh->prepare($query) || die "failed to create insert into parts query" . $dbh->errstr;
296 $eth->execute($code,$desc,$price,$price) || die "failed to execute insert into parts query" . $dbh->errstr;
297 $dbh->commit || die $dbh->errstr;
298 $eth->finish || die "cannot finish " . $dbh->errstr;
300 $retval = get_partid
($myconfig, $form, $code);