3 use Frontier
::Responder
;
6 # You need to modify this as needed:
7 use lib qw
(/srv/www
/sql
-ledger
);
16 require "sql-ledger.conf";
18 my $add_customer = \
&rpc_add_customer
;
19 my $add_salesman = \
&rpc_add_employee
;
20 my $add_invoice = \
&rpc_add_invoice
;
21 my $customer_balance = \
&rpc_customer_balance
;
23 my $res = Frontier
::Responder
->new( methods
=> {
24 'ezybiz.add_invoice' => $add_invoice,
25 'ezybiz.add_salesman' => $add_salesman,
26 'ezybiz.customer_balance' =>$customer_balance,
27 'ezybiz.add_customer' => $add_customer
32 sub rpc_customer_balance
{
34 if ($$post_hash{id
} > 0 ) {
35 my $myconfig = new User
"$memberfile", "$oemr_username";
36 $myconfig->{dbpasswd
} = unpack 'u', $myconfig->{dbpasswd
};
38 $form->{title
} = "AR Outstanding";
39 $form->{outstanding
} = "1";
40 $form->{customer_id
} = $$post_hash{id
};
41 $form->{sort} = "transdate" ;
43 $form->{nextsub
} = "ar_transaction";
44 $form->{action
} = 'Continue';
46 AR
::ar_transactions
("",\
%$myconfig, \
%$form);
47 my ($paid,$amount) =0;
49 # Exclude invoices that are not yet due (i.e. waiting for insurance).
52 my $today = sprintf("%04u-%02u-%02u", $now[5] + 1900, $now[4] + 1, $now[3]);
53 foreach my $resref (@
{$$form{transactions
}}) {
54 my $duedate = substr($$resref{duedate
}, 6) . "-" . substr($$resref{duedate
}, 0, 5);
55 if ($duedate le $today) {
56 $paid += $$resref{paid
};
57 $amount += $$resref{amount
};
61 my $retval = $amount - $paid;
68 use lib
'/usr/lib/perl5/site_perl/5.8.3';
72 #take struct of data and map to post data to create the customer, return the id
73 my $myconfig = new User
"$memberfile", "$oemr_username";
74 $myconfig->{dbpasswd
} = unpack 'u', $myconfig->{dbpasswd
};
76 $form->{name
} = substr($$post_hash{'firstname'} . " " . $$post_hash{'lastname'}, 0, 64);
77 $form->{discount
} = "";
79 $form->{taxincluded
} = "1";
80 $form->{creditlimit
} = "0";
81 $form->{id
} = $$post_hash{'foreign_id'};
83 $form->{employee
} = "";
84 $form->{pricegroup
} = "";
85 $form->{business
} = "";
86 $form->{language
} = "";
87 $form->{address1
} = substr($$post_hash{'address'}, 0, 32);
88 $form->{address2
} = substr($$post_hash{'address'}, 32, 32);
89 $form->{city
} = substr($$post_hash{'suburb'}, 0, 32);
91 if($$post_hash{'state'}){
92 $form->{state} = substr($$post_hash{'state'}, 0, 32);
94 $form->{state} = substr($$post_hash{'geo_zone_id'}, 0, 32);
96 $form->{zipcode
} = substr($$post_hash{'postcode'}, 0, 10);
97 $form->{country
} = "";
98 $form->{contact
} = "";
99 $form->{phone
} = substr($$post_hash{'phone1'}, 0, 20);
101 $form->{email
} = $$post_hash{'email'};
102 $form->{taxnumber
} = substr($$post_hash{'ssn'}, 0, 32);
103 $form->{curr
} = "USD";
104 $form->{customernumber
} = $$post_hash{'customernumber'};
105 @t = localtime(time);
110 $form->{startdate
} = "$mm-$dd-$yy";
112 CT
::save_customer
('', \
%$myconfig, \
%$form);
113 my $retVal = $form->{id
};
120 my ($post_hash) = @_;
121 my $myconfig = new User
"$memberfile", "$oemr_username";
122 $myconfig->{dbpasswd
} = unpack 'u', $myconfig->{dbpasswd
};
124 $form->{id
} = $$post_hash{'foreign_id'};
125 $form->{name
} = $$post_hash{'fname'} . " " . $$post_hash{'lname'};
126 $form->{sales
} = $$post_hash{'authorized'};
127 @t = localtime(time);
132 $form->{startdate
} = "$mm-$dd-$yy";
133 HR
::save_employee
("",\
%$myconfig, \
%$form);
134 my $retVal = $form->{id
};
140 my ($post_hash) = @_;
142 my $myconfig = new User
"$memberfile", "$oemr_username";
143 $myconfig->{dbpasswd
} = unpack 'u', $myconfig->{dbpasswd
};
146 $form->{employee
} = "--" . $$post_hash{'salesman'};
147 $form->{customer_id
} = $$post_hash{'customerid'};
148 $form->{invnumber
} = $$post_hash{'invoicenumber'};
149 $form->{amount
} = $$post_hash{'total'};
150 $form->{netamount
} = $$post_hash{'total'};
151 $form->{notes
} = $$post_hash{'notes'};
152 $form->{department
} = "";
153 $form->{currency
} = "USD";
154 $form->{defaultcurrency
} = "USD";
156 # This is the AR account number, needed by IS::post_invoice.
157 $form->{AR
} = $oemr_ar_acc;
159 # This will use the posting date as the billing date
160 @t = localtime(time);
165 $form->{transdate
} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900);
167 # This overrides the above statement to use the date of service as the
168 # invoice date, which should be preferable for most practices. Comment
169 # out the following line if you really want the billing date instead.
171 $form->{transdate
} = $$post_hash{'dosdate'};
173 # If there is insurance, set a future due date so we don't bother
174 # the patient for a while.
176 if ($$post_hash{'payer_id'}) {
177 @t = localtime(60 * 60 * 24 * $oemr_due_days + time);
178 $form->{duedate
} = sprintf("%02u-%02u-%04u", $t[4] + 1, $t[3], $t[5] + 1900);
180 $form->{duedate
} = $form->{transdate
};
183 # Get out if the invoice already exists.
185 my $dbh = $form->dbconnect($myconfig);
186 my $query = qq|SELECT id FROM ar WHERE invnumber
= ?
|;
187 my $eth = $dbh->prepare($query) || die "Failed to prepare ar query";
188 $eth->execute($$post_hash{'invoicenumber'}) || die "Failed to execute ar query";
189 ($trans_id) = $eth->fetchrow_array;
193 print STDERR
"Skipping invoice $trans_id = " . $$post_hash{'invoicenumber'} . "\n";
197 #loop through line items and add them to invoice
199 my $j = 1; #this is for copays should only be one but who knows -j
201 my $items = $$post_hash{'items'};
203 foreach my $line_item (@
$items)
205 if($$line_item{'itemtext'} =~ /COPAY/){
206 $form->{"datepaid_$j"} = "$mm-$dd-$yy";
207 $form->{"source_$j"} = "Co-pay";
208 $form->{"memo_$j"} ='Co-pay';
209 $form->{"paid_$j"} = abs($$line_item{'price'});
210 $form->{"AR_paid_$j"} = "$oemr_cash_acc" . "--";
214 $form->{"qty_$i"} = $$line_item{'qty'};
215 $form->{"discount_$i"} = 0;
216 $form->{"sellprice_$i"} = $$line_item{'price'};
218 $form->{taxincluded
} = 1;
219 $form->{"taxaccounts_$i"} = 0;
220 $form->{"income_accno_$i"} = $$line_item{'glaccountid'};
222 $form->{"id_$i"} = add_goodsandservices
(\
%$myconfig, \
%$form, $oemr_services_partnumber,
223 'Medical Services', '');
225 $form->{"description_$i"} = $$line_item{'itemtext'};
226 $form->{"unit_$i"} = '';
227 $form->{"serialnumber_$i"} = $$line_item{'maincode'};
229 # Save the insurance company ID as the SL project ID. This gives us a way
230 # to associate each invoice item with its insurance payer. The clinic will
231 # probably want to write some reporting software taking advantage of this.
233 $form->{"projectnumber_$i"} = "--" . $$post_hash{'payer_id'}
234 if ($$post_hash{'payer_id'});
239 $form->{paidaccounts
} = $j - 1;
240 $form->{rowcount
} = $i - 1;
241 IS
::post_invoice
("", \
%$myconfig, \
%$form);
242 my $retVal = $form->{id
};
248 my ($myconfig, $form, $number) = @_;
250 # connect to database
251 my $dbh = $form->dbconnect($myconfig);
253 my $query = qq|SELECT id FROM parts WHERE partnumber
= ?
|;
254 my $eth = $dbh->prepare($query) || die "Failed to create select id from parts query";
255 $eth->execute($number) || die "Failed to execute select id from parts query";
256 ($retval) = $eth->fetchrow_array;
262 sub add_goodsandservices
264 my ($myconfig, $form, $code, $desc, $price) = @_;
266 $retval = get_partid
($myconfig, $form, $code);
270 # connect to database, turn off autocommit
271 my $dbh = $form->dbconnect_noauto($myconfig);
272 my $query = qq|insert into parts
(partnumber
,description
,listprice
,sellprice
) values(?
,?
,?
,?
)|;
273 my $eth = $dbh->prepare($query) || die "failed to create insert into parts query" . $dbh->errstr;
274 $eth->execute($code,$desc,$price,$price) || die "failed to execute insert into parts query" . $dbh->errstr;
275 $dbh->commit || die $dbh->errstr;
276 $eth->finish || die "cannot finish " . $dbh->errstr;
278 $retval = get_partid
($myconfig, $form, $code);