Compare commits

..

67 Commits

Author SHA1 Message Date
abijah 30c6e0b0f4 Forgot to save the file before the last checkin. Added the possibility of a 'credits' table, but I'll probably be wiping this out moving forward.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@68 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-04 03:48:35 +00:00
abijah 46e3316ce1 Added some changes to try and resolve some accounting problems. However, I may be about to redo the accounting stuff altogether.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@67 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-04 01:56:09 +00:00
abijah e1671a9fca Additional work on generating ledger information. I've been reading up on accounting basics though, and I feel I'm just not going in the right direction. I'm checking this in, since it works somewhat, and will probably try to head in a different direction.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@66 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-04 01:54:15 +00:00
abijah e586268dee Added a couple helpers, including Html, to our app controller and removed Html from each individual controller
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@65 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-03 22:33:03 +00:00
abijah 24730fda1b Added links everywhere for charge/payment/receipt. Also, minor tweaking to the views in a couple places.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@64 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 08:39:33 +00:00
abijah b6ec85205d Added the payments controller and views.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@63 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 08:15:51 +00:00
abijah b6a0809350 Added the charges controller and views. Fixed a couple minor bugs found with receipts.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@62 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 08:05:53 +00:00
abijah f42ce65768 Changed the charge_to date to allow NULL, since not all charges cover a time period (security deposits, some late charges, POS, etc)
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@61 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 07:26:00 +00:00
abijah ef180e7dda Added a receipt controller to verify receipt data
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@60 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 07:24:51 +00:00
abijah 4aa59a40a2 Removed the test code I'd forgot and left in the table element
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@59 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 07:23:42 +00:00
abijah 0c43a0f884 Fixed copy/paste error
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@58 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 07:23:05 +00:00
abijah e65db5c759 Rolled back the last changes, which were checked in for documentation only.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@57 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 06:28:56 +00:00
abijah 59b549955e Added payments under each receipt in the ledger. This isn't something I really want, just something I was testing. Snapshotting before I delete it, since it did work correctly
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@56 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 06:25:59 +00:00
abijah 603a08393e Moved the view action to use the Containable behavior instead of the convoluted bind/unbind
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@55 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 06:17:49 +00:00
abijah 1db887cf38 Removed the debug comments that were helping me with the sitelink migration, and added in the actual comments that were entered in sitelink.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@54 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 05:44:44 +00:00
abijah 4ebe1db2cc Cleaned up the controllers and now make use of the Linkable behavior for listing out items.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@53 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 04:36:28 +00:00
abijah f74073a2e1 Cleaned up the paginate comment remnants and added the undocumented 'extra' parameter to paginate
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@52 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 04:30:32 +00:00
abijah 3f6c526718 Removed the named table alias from each of the HABTM joins, since we don't know in advance what name will be used in the actual join
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@51 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 04:29:26 +00:00
abijah 903209a47e Performed cleanup, and started the thought process of figuring out how to use one link table multiple times in the same query. My changes worked actually, but I want to wait on this to see if I can figure out if there is already a core solution (since it seems likely that things behaving like a tree would have one table used multiple times in the same query... although they probably get around that by running 100 different queries come to think of it).
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@50 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 04:27:34 +00:00
abijah 23a81ae924 I've been around and around with paging. I started using the Containable behavior, which is fantastic for something like 'view', but is highly problematic for listings, especially with pagination. I discovered the Linkable behavior, and it's much more database efficient, and I actually can get it to work with pagination (except when using GROUP BY). I did have to tweak it though, to handle some of the more complex queries that I intend. This checkin includes a bunch of garbage, but given the amount of time I've spent on this crap, I'm afraid to lose anything that might later be useful information. I'll clean up on the next checkin.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@49 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 02:36:26 +00:00
abijah 9db4dd737d Added some of the original formatting back into the sql log table.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@48 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 02:11:48 +00:00
abijah 52528f1c0e Minor tweak to the table headers
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@47 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-06-01 02:11:14 +00:00
abijah 6bf06a3a3c Changed how fields are handled, so that they are all included by default and the user is not forced to specify them. This works with paginate, but the additional fields are requested in the count query. Would like to resolve this, but it doesn't seem to be confusing paginate.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@46 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-31 18:27:21 +00:00
abijah 387c1ae87b Testing out a possible model behavior called linkable. I may not go this route, but I'll just delete it if not.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@45 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-31 17:02:41 +00:00
abijah 70812e0a0c Getting sidemenu ready for more dynamic actions based on context. Couple minor tweaks to layout.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@44 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-30 20:51:07 +00:00
abijah 7fae1bcaad Modified table element algorithm to be cleaner and to handle multiple class types. Modified ledger listings to group the charges and associated payment rows with one color. Fixed summary balance data to come from the controller instead of being created in the view. Created an infobox to carry pertinent info in the top right of the view pages.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@43 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-30 20:07:24 +00:00
abijah c041174b0c Changed how tables are layed out (since I was repeatedly duplicating code in many places) by adding a table element to be used wherever we need a table. This could probably have been a helper instead of an element, but it's not clear to me why one should be chosen over the other, and I already know how to quickly add an element (I think the real choice resides in whether you need a collection of helper functions, or you just want to drop in a chunk of html, i.e. a helper element). Also, a major revamp to the style sheets as well, although more work is clearly needed.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@42 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-30 15:56:41 +00:00
abijah 2a4b8079fb Added comment blocks and context specific side menu link items. Also tweaked the Page titles and headings for the table listings.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@41 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 16:01:47 +00:00
abijah 79bcf99fc5 Removed unnecessary sidemenu links function, as the overriding class can just call the parent to get the standard links.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@40 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 15:55:50 +00:00
abijah 9d09afca35 Minor CSS layout tweak
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@39 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 15:54:33 +00:00
abijah f384e051bf Initial working version ofa consistent layout with side menu
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@38 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 14:49:11 +00:00
abijah 2da7b6b2c0 Added a higher preference for horizontal unit names
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@37 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 06:57:22 +00:00
abijah 2c85566ffc The map is working quite well now, including the legend. Next steps will be to add the sidemenu.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@36 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 05:10:46 +00:00
abijah db03c73b59 Fixed the underlying hotlink map to match the coordinates of the actual image. Also fixed a few issues with requested_width propogation, although there may still be some bugs.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@35 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 04:37:24 +00:00
abijah 684f02ebc5 More tweaks to get the map working. At the moment, the clickable area is off because it's not scaled like the actual image is. I'll have to work on that next.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@34 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 03:36:28 +00:00
abijah 4e33c58246 Further progress on the site map. The scale is off at the moment, but it's working well enough that it's worth a snapshot.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@33 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 02:45:23 +00:00
abijah 9fc5562dd8 Adding mapping ability. Incomplete as of yet, but coming along nicely.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@32 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-29 01:47:12 +00:00
abijah 3cc8e95ff4 Added a name for our lone map
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@31 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 23:18:20 +00:00
abijah 15930fae30 Moved the unit status logic into the model where it belongs.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@30 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 22:09:04 +00:00
abijah dbe037fee8 Added support for querying only occupied or vacant units. It's working at the moment, but I'll probably move some more logic to the controller next.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@29 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 21:52:14 +00:00
abijah 5c6189cdef Added preliminary support for units. The queries are giving me a heck of a time, so I've cheated in some places. For the most part though, it's working. Also, something went wrong with svn, and view/contacts/view.ctp was not right (a checkin seems to have been omitted on it). This checking brings it up to date.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@28 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 11:26:09 +00:00
abijah 4a86d3dda0 Removal of site_id from the maps table, corresponding with the last checkin
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@27 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 11:09:56 +00:00
abijah ec3d986c78 Removed site_id from the maps table, since the it already references site_area_id which fully qualifies the site anyway.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@26 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 11:09:19 +00:00
abijah e38e99c94e Removed the revisit code, as use of it would only screw up pagination anyway.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@25 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 09:36:58 +00:00
abijah aed2c6912c Added more models
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@24 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 09:27:29 +00:00
abijah 7433e6868c Fixed duplicate row entries and other paginate issues. The fix might be a hack, but it works for now.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@23 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 09:07:53 +00:00
abijah 8393403443 First pass at listing the customers. Need to figure out how to paginate based on a HABTM relationship.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@22 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 08:04:22 +00:00
abijah ed04f81dda Modified to allow the display_name to be NULL
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@21 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 08:03:12 +00:00
abijah 4923712238 Moved the contact info into the contacts controller.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@20 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 07:12:32 +00:00
abijah ffe04ed6fd Added Lease History and security deposit tracking.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@19 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 07:05:05 +00:00
abijah 0021eb1768 Changed the charge/receipt comments slightly to help clarify the intent.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@18 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 06:42:20 +00:00
abijah 0ef51ee30f Added a Financial Accounts table, for allowing transactions to be exported to financial software (definition is presently incomplete). Rearranged the table definitions a bit as well.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@17 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 06:40:40 +00:00
abijah 28bf192853 Added phone and address models as well as outputing them to the view.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@16 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 06:31:07 +00:00
abijah df846f9963 Very, very early snapshot. Some models are working, and I have a controller for testing. Everything is subject to change. I _do_ have a working tenant ledger though, so it's worth a snapshot.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@15 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-28 05:49:03 +00:00
abijah f4007a0269 Adjusted database details and sitelink conversion script to go along with new schema naming convention changes
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@14 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 20:54:14 +00:00
abijah 6b53d8a25a Omission bug on last checkin
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@13 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 20:52:32 +00:00
abijah 76a06d1655 Further naming conventions to match CakePHP
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@12 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 20:49:54 +00:00
abijah eeb8775820 Further changes to the table naming conventions to match expectations of CakePHP
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@11 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 20:32:31 +00:00
abijah 2d9a85ad82 Changed table naming convention
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@10 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 20:25:00 +00:00
abijah 0da1080b86 Added database schema file. For the complete revision history of schema.sql, see branches/rent_manager_20090510/db path of the 'domain' repository
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@9 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 19:47:48 +00:00
abijah 2665d012c2 Added a scripts directory and the latest copy of our sitelink conversion script. For the complete revision history of sitelink2pmgr.pl, see branches/rent_manager_20090510 path of the 'domain' repository
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@8 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 19:26:04 +00:00
abijah c5d5e2c651 Removed the cache files from the repository
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@7 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 19:23:05 +00:00
abijah c22be388cf Fixed the stupid svn:ignore properties, which all had a trailing space (doh!)
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@6 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 04:35:43 +00:00
abijah 220284d20f Added svn:ignore for all of the tmp directories
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@5 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 04:24:45 +00:00
abijah 4502b73b2e Load pmgr into branches/initial_20090526/site.
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@4 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 04:18:23 +00:00
abijah 3251ba340d Create directories to load project into.
* branches/initial_20090526/site: New directory.


git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@3 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 04:18:18 +00:00
Abijah c9f9d0867b Added branch point for initial work. The site directory will be added using the svn_import script, and will represent the output of the command 'cake bake pmgr'
git-svn-id: file:///svn-source/pmgr/branches/initial_20090526@2 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-05-27 04:17:45 +00:00
92 changed files with 2182 additions and 0 deletions
+1199
View File
File diff suppressed because it is too large Load Diff
+983
View File
@@ -0,0 +1,983 @@
#perl -w
use strict;
use DBI;
use Data::Dumper;
use File::Copy;
# Internally adjust all numbers coming from the database to
# be in inches. Not necessary to go to this detail, but the
# actual units used is irrelevant, provided everything is to
# scale, and this factor ensures that any fractional units
# become whole (e.g. 7.5 "feet" becomes 90 "units")
my $internal_adjustment_factor = 12;
my $schema_file = shift || die("Must specify schema file\n");
my $slink_file = shift || die("Must specify sitelink file\n");
my $slink_file = ";Data Source=$slink_file";
my $slink_pass = ";Jet OLEDB:Database Password=2web";
my $sdsn="Provider=Microsoft.Jet.OLEDB.4.0$slink_pass$slink_file";
my $sdbh = DBI->connect("dbi:ADO:$sdsn", undef, undef, {PrintError => 1,
RaiseError => 1});
# Connect to the database.
my($hostname, $database, $user, $password) = ('localhost',
'property_manager',
'pmgr', 'pmgruser');
my $db_handle = DBI->connect("DBI:mysql:database=$database;host=$hostname",
$user, $password,
{'RaiseError' => 1});
my ($query, $result, $nrows, $row);
my ($aicur_c_id, $aicur_ca_id, $aicur_cp_id, $aicur_ce_id) = (0, 0, 0, 0);
my ($aicur_g_id, $aicur_gp_id, $aicur_user_id) = (0, 0, 0);
my ($aicur_type_id, $aicur_size_id, $aicur_unit_id) = (0, 0, 0);
my ($aicur_site_id, $aicur_area_id) = (0, 0);
my ($aicur_lease_type_id, $aicur_lease_id) = (0, 0);
my ($aicur_charge_id, $aicur_receipt_id, $aicur_payment_id) = (0, 0, 0);
open(SCHEMA, "<$schema_file") || die ("Can't open schema ($!)\n");
my $schema_query = "";
while (<SCHEMA>) {
next if /^\s*-- /;
$schema_query .= $_;
query($db_handle, $schema_query), $schema_query = ""
if /;\s*$/;
}
close(SCHEMA);
++$aicur_c_id;
$query = "INSERT INTO pmgr_contacts
(`id`, `first_name`, `middle_name`, `last_name`, `display_name`) VALUES
($aicur_c_id, 'Abijah', 'M', 'Perkins', 'Perkins, Abijah')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_ca_id;
$query = "INSERT INTO pmgr_contact_addresses
(`id`, `address`, `city`, `state`, `postcode`, `country`) VALUES
($aicur_ca_id, '1324 N Liberty Lake Rd\nPMB 263', 'Liberty Lake', 'WA', '99019', 'USA')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'POST', $aicur_ca_id, 'MAIN', 'PRIMARY')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_ca_id;
$query = "INSERT INTO pmgr_contact_addresses
(`id`, `address`, `city`, `state`, `postcode`, `country`) VALUES
($aicur_ca_id, '5221 W Myrtlewood Ct', 'Spokane', 'WA', '99208', 'USA')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'POST', $aicur_ca_id, 'HOME', 'ALTERNATE')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_ca_id;
$query = "INSERT INTO pmgr_contact_addresses
(`id`, `address`, `city`, `state`, `postcode`, `country`) VALUES
($aicur_ca_id, 'PO Box 69', 'Granger', 'WA', '98932', 'USA')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'POST', $aicur_ca_id, 'HOME', 'ALTERNATE')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_cp_id;
$query = "INSERT INTO pmgr_contact_phones
(`id`, `type`, `phone`) VALUES
($aicur_cp_id, 'MOBILE', '5098445573')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'PHONE', $aicur_cp_id, 'MAIN', 'PRIMARY')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_cp_id;
$query = "INSERT INTO pmgr_contact_phones
(`id`, `type`, `phone`) VALUES
($aicur_cp_id, 'MOBILE', '5098445973')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'PHONE', $aicur_cp_id, 'MAIN', 'ALTERNATE')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_cp_id;
$query = "INSERT INTO pmgr_contact_phones
(`id`, `type`, `phone`) VALUES
($aicur_cp_id, 'VIRTUAL', '5095901112')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'PHONE', $aicur_cp_id, 'BUSINESS', 'WORK')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_cp_id;
$query = "INSERT INTO pmgr_contact_phones
(`id`, `type`, `phone`) VALUES
($aicur_cp_id, 'LANDLINE', '5098541491')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'PHONE', $aicur_cp_id, 'HOME', 'ALTERNATE')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_cp_id;
$query = "INSERT INTO pmgr_contact_phones
(`id`, `type`, `phone`) VALUES
($aicur_cp_id, 'VIRTUAL', '8774488664')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'PHONE', $aicur_cp_id, 'BUSINESS', 'WORK')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_cp_id;
$query = "INSERT INTO pmgr_contact_phones
(`id`, `type`, `phone`) VALUES
($aicur_cp_id, 'FAX', '8662960131')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'PHONE', $aicur_cp_id, 'BUSINESS', 'WORK')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_ce_id;
$query = "INSERT INTO pmgr_contact_emails
(`id`, `email`) VALUES
($aicur_ce_id, 'abijah\@PerkinsHouse.com')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'EMAIL', $aicur_ce_id, 'HOME', 'PRIMARY')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_ce_id;
$query = "INSERT INTO pmgr_contact_emails
(`id`, `email`) VALUES
($aicur_ce_id, 'abijah\@PerkinsREI.com')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'EMAIL', $aicur_ce_id, 'HOME', 'WORK')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_ce_id;
$query = "INSERT INTO pmgr_contact_emails
(`id`, `email`) VALUES
($aicur_ce_id, 'abijah\@ValleyStorage.com')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($aicur_c_id, 'EMAIL', $aicur_ce_id, 'BUSINESS', 'WORK')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_g_id;
$query = "INSERT INTO pmgr_groups
(`id`, `code`, `name`)
VALUES
($aicur_g_id, 'Owner', 'Owner Group')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_gp_id;
$query = "INSERT INTO pmgr_group_permissions
(`group_id`, `name`, `access`)
VALUES
($aicur_gp_id, 'EVERYTHING', 'FORCED')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_user_id;
$query = "INSERT INTO pmgr_users
(`id`, `code`, `login`, `contact_id`)
VALUES
($aicur_user_id, 'AP', 'abijah', $aicur_c_id)";
query($db_handle, $query) || die("Unable to insert");
++$aicur_site_id;
$query = "INSERT INTO pmgr_sites
(`id`, `code`, `name`)
VALUES
($aicur_site_id, 'VSS', 'Valley Storage')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_site_memberships
(`site_id`, `user_id`, `group_id`)
VALUES
($aicur_site_id, $aicur_user_id, $aicur_g_id)";
query($db_handle, $query) || die("Unable to insert");
++$aicur_area_id;
$query = "INSERT INTO pmgr_site_areas
(`id`, `site_id`, `code`, `name`)
VALUES
($aicur_area_id, $aicur_site_id, 'Main', 'Main Facility Area')";
query($db_handle, $query) || die("Unable to insert");
++$aicur_lease_type_id;
$query = "INSERT INTO pmgr_lease_types
(`id`, `code`, `name`)
VALUES
($aicur_lease_type_id, 'SL', 'Storage Lease')";
query($db_handle, $query) || die("Unable to insert");
######################################################################
######################################################################
## query
sub query {
my ($dbh, $sql) = @_;
#print("$sql\n\n"); #return [ { 'id' => 7 } ];
#print("$sql\n\n") if $sql =~ /^\s*UPDATE/i;
#return 1 unless $sql =~ /^\s*SELECT/i;
my ($sth, $result);
if ($sql =~ /^\s*SELECT/i) {
$sth = $dbh->prepare($sql);
$sth->execute();
$result = $sth->fetchall_arrayref({});
} else {
$result = $dbh->do($sql);
}
#print("sth = " . Dumper($sth) . "\n");
#print("result = " . Dumper($result) . "\n");
return ($sth, $result);
}
sub sizeCode {
my ($width, $depth) = @_;
return "YARD"
if ($width == 12 && $depth == 40);
return "APARTMENT"
if ($width == 20 && $depth == 30);
return sprintf("%02dx%02d", $width, $depth);
}
sub datefmt {
my ($dt) = @_;
return undef unless $dt;
my @dt = split(/\/|\s/, $dt);
#print("$dt : " . sprintf("%04d-%02d-%02d", $dt[2], $dt[0], $dt[1]) . "\n");
return sprintf("%04d-%02d-%02d%s", $dt[2], $dt[0], $dt[1], $dt[3] ? ' '.$dt[3] : "");
}
######################################################################
######################################################################
######################################################################
######################################################################
######################################################################
######################################################################
##
## UNITS
##
######################################################################
## Unit Types
$query = "SELECT * FROM UnitType ORDER BY TypeID";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Unit Types\n");
foreach $row (@$result) {
$query = "INSERT INTO pmgr_unit_types
(`id`, `code`, `name`)
VALUES
($row->{'TypeID'}, 'xxx', '$row->{'UnitType'}')";
query($db_handle, $query) || die("Unable to insert");
}
######################################################################
## Unit Sizes
$query = "SELECT * FROM UnitInfo WHERE UnitID <> 'POS\$' ORDER BY UnitID";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Units\n");
my (%unit_size_map);
foreach $row (@$result) {
my $sz = sizeCode($row->{'Width'}, $row->{'Depth'});
next if defined $unit_size_map{$sz};
$unit_size_map{$sz} = { 'id' => ++$aicur_size_id };
$unit_size_map{$sz}{'rent'} = $row->{'StdRent'};
$unit_size_map{$sz}{'dep'} = $row->{'StdSecDep'};
my $szid = $unit_size_map{$sz}{'id'};
$query = "INSERT INTO pmgr_unit_sizes
(`id`, `unit_type_id`, `code`, `name`, `width`, `depth`,
`deposit`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($szid, $row->{'Type'}, $sz, $sz,
$internal_adjustment_factor * $row->{'Width'},
$internal_adjustment_factor * $row->{'Depth'},
$row->{'StdSecDep'}, $row->{'StdRent'})
)) . ")";
query($db_handle, $query) || die("Unable to insert");
}
######################################################################
## Units
my (%unit_map);
foreach $row (@$result) {
my $sz = sizeCode($row->{'Width'}, $row->{'Depth'});
my $szid = $unit_size_map{$sz}{'id'};
$unit_map{$row->{'UnitID'}} = ++$aicur_unit_id;
my $uid = $unit_map{$row->{'UnitID'}};
$query = "INSERT INTO pmgr_units
(`id`, `unit_size_id`, `code`, `name`,
`status`,
`sort_order`, `walk_order`, `deposit`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($uid, $szid, $row->{'UnitID'}, $row->{'UnitID'},
$row->{'Rented'} ?'OCCUPIED' :($row->{'Rentable'} ?'VACANT' :'UNAVAILABLE'),
$uid, $uid, $row->{'StdSecDep'}, $row->{'StdRent'})
)) . ")";
query($db_handle, $query) || die("Unable to insert");
}
######################################################################
## Map
my %info = ('extents' => {}, 'units' => {});
# Get the overall site limits
$query = "SELECT MIN(M.Top) AS mintop, MIN(M.Left) AS minlft,";
$query .= " MAX(M.Top + IIF(M.reverseWL, U.Width, U.Depth)) AS bot,";
$query .= " MAX(M.Left + IIF(M.reverseWL, U.Depth, U.Width)) AS rgt";
$query .= ' FROM UnitInfo U INNER JOIN mapUnitsV2 M ON M.unitID = U.UnitID';
$result = query($sdbh, $query);
# Fetch and verify the result
my $row = shift(@$result);
die("MIN query failed!") unless $row;
# Compute the actual boundaries, adjusting for a (0,0) origin
my $top_adjustment = 0 - $row->{'mintop'};
my $left_adjustment = 0 - $row->{'minlft'};
$info{'extents'}{'top'} = 0;
$info{'extents'}{'left'} = 0;
$info{'extents'}{'bottom'} = $internal_adjustment_factor * ($top_adjustment + $row->{'bot'} + 0);
$info{'extents'}{'right'} = $internal_adjustment_factor * ($left_adjustment + $row->{'rgt'} + 0);
$query =
"INSERT INTO pmgr_maps (id, name, site_area_id, width, depth) VALUES\n" .
" (1, 'Main Facility Map', $aicur_area_id," .
($info{'extents'}{'right'} - $info{'extents'}{'left'}) . ", " .
($info{'extents'}{'bottom'} - $info{'extents'}{'top'}) . ")";
query($db_handle, $query) || die("Unable to insert");
# Get list of units and positions
$query = "SELECT U.UnitID, U.UnitID as name,";
$query .= " ($top_adjustment + M.Top) AS pt_t,";
$query .= " ($left_adjustment + M.Left) AS pt_l,";
$query .= " IIF(M.reverseWL, U.Depth, U.Width) AS Width,";
$query .= " IIF(M.reverseWL, U.Width, U.Depth) AS Depth,";
$query .= " M.reverseWL, U.Rented, U.Rentable";
$query .= " FROM UnitInfo U INNER JOIN mapUnitsV2 M ON M.unitID = U.UnitID";
$result = query($sdbh, $query);
# Go through each one, calculating the map location
foreach $row (@$result) {
my $uid = $unit_map{$row->{'UnitID'}};
$query = # pt_bottom, pt_right,
"INSERT INTO pmgr_maps_units (map_id, unit_id,
pt_top, pt_left,
transpose) VALUES
(" . join(", ",
1, $uid,
$internal_adjustment_factor * ($row->{'pt_t'}),
$internal_adjustment_factor * ($row->{'pt_l'}),
$row->{'reverseWL'}) . ")";
query($db_handle, $query) || die("Unable to insert");
}
######################################################################
######################################################################
######################################################################
######################################################################
######################################################################
######################################################################
##
## TENANTS
##
######################################################################
## Tenants
$query = "SELECT * FROM TenantInfo WHERE FirstName <> 'POS' ORDER BY TenantID";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Tenants\n");
my %stmap = ( 1=>'AK', 14=>'ID', 48=>'WA' );
my (%tenant_map);
foreach $row (@$result) {
$tenant_map{$row->{'TenantID'}} = { 'id' => ++$aicur_c_id };
my $cid = $tenant_map{$row->{'TenantID'}}{'id'};
$query = "INSERT INTO pmgr_contacts
(`id`, `first_name`, `middle_name`, `last_name`, `display_name`, `id_local`, `id_local_state`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($cid, $row->{'FirstName'}, $row->{'MiddleName'}, $row->{'LastName'},
"$row->{'LastName'}, $row->{'FirstName'}",
$row->{'IDNum'} || undef, $row->{'IDNum'} ? $stmap{$row->{'DLStateID'}} : undef)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
if ($row->{'City'}) {
$query = "INSERT INTO pmgr_contact_addresses
(`id`, `address`, `city`, `state`, `postcode`, `country`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(++$aicur_ca_id,
#$row->{'HomeAddress'}
$row->{'HomeAddress'} . ($row->{'HomeAddr2'} ? "\n".$row->{'HomeAddr2'} : "") || undef,
$row->{'City'}, $stmap{$row->{'StateID'}}, $row->{'Zip'} || undef, 'USA')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($cid, 'POST', $aicur_ca_id, 'HOME', 'PRIMARY')";
query($db_handle, $query) || die("Unable to insert");
}
foreach ({'type' => 'LANDLINE', 'preference' => 'PRIMARY', 'phone' => $row->{'Phone'}},
{'type' => 'LANDLINE', 'preference' => 'WORK',
'phone' => $row->{'BusinessPhone'}, 'ext' => $row->{'BusinessExt'}},
{'type' => 'FAX', 'preference' => 'PRIMARY', 'phone' => $row->{'FAX'}},
{'type' => 'PAGER', 'preference' => 'PRIMARY', 'phone' => $row->{'Pager'}},
{'type' => 'MOBILE', 'preference' => 'ALTERNATE', 'phone' => $row->{'CellPhone'}})
{
if ($_->{'phone'}) {
$query = "INSERT INTO pmgr_contact_phones
(`id`, `type`, `phone`, `ext`) VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(++$aicur_cp_id, $_->{'type'}, $_->{'phone'}, $_->{'ext'})))
. ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($cid, 'PHONE', $aicur_cp_id, 'MAIN', $_->{'preference'})))
. ")";
query($db_handle, $query) || die("Unable to insert");
}
}
if ($row->{'Email'}) {
$query = "INSERT INTO pmgr_contact_emails
(`id`, `email`) VALUES
(".++$aicur_ce_id.", '$row->{'Email'}')";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUE
($cid, 'EMAIL', $aicur_ce_id, 'MAIN', 'PRIMARY')";
query($db_handle, $query) || die("Unable to insert");
}
next unless $row->{'AltFirstName'} || $row->{'AltLastName'} || $row->{'AltAddress'} || $row->{'AltPhone'};
$tenant_map{$row->{'TenantID'}}{'alt'} = ++$aicur_c_id;
$cid = $tenant_map{$row->{'TenantID'}}{'alt'};
$query = "INSERT INTO pmgr_contacts
(`id`, `first_name`, `middle_name`, `last_name`, `display_name`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($cid,
$row->{'AltFirstName'} || undef,
$row->{'AltMI'} || undef,
$row->{'AltLastName'} || undef,
($row->{'AltLastName'} && $row->{'AltFirstName'}
? "$row->{'AltLastName'}, $row->{'AltFirstName'}"
: ($row->{'AltLastName'} || $row->{'AltFirstName'} || undef)))
)) . ")";
query($db_handle, $query) || die("Unable to insert");
if ($row->{'AltCity'}) {
$query = "INSERT INTO pmgr_contact_addresses
(`id`, `address`, `city`, `state`, `postcode`, `country`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(++$aicur_ca_id,
$row->{'AltAddress'} . ($row->{'AltAddr2'} ? "\n".$row->{'AltAddr2'} : ""),
$row->{'AltCity'}, $stmap{$row->{'AltStateID'}}, $row->{'AltZip'}, 'USA')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($cid, 'POST', $aicur_ca_id, 'MAIN', 'PRIMARY')";
query($db_handle, $query) || die("Unable to insert");
}
if ($row->{'AltPhone'}) {
$query = "INSERT INTO pmgr_contact_phones
(`id`, `type`, `phone`, `ext`) VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(++$aicur_cp_id, 'LANDLINE', $row->{'AltPhone'}, undef)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_methods
(`contact_id`, `method`, `method_id`, `type`, `preference`) VALUES
($cid, 'PHONE', $aicur_cp_id, 'MAIN', 'PRIMARY')";
query($db_handle, $query) || die("Unable to insert");
}
}
######################################################################
## Tenant Leases
$query = "SELECT L.*, A.TenantID FROM TenantLedger L LEFT JOIN `Access` A ON A.LedgerID = L.LedgerID WHERE L.UnitID <> 'POS\$' ORDER BY L.LedgerID";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Tenant Ledgers\n");
my (%ledger_map);
foreach $row (@$result) {
$ledger_map{$row->{'LedgerID'}} = ++$aicur_lease_id;
my $cid = $tenant_map{$row->{'TenantID'}}{'id'};
my $uid = $unit_map{$row->{'UnitID'}};
my $lid = $ledger_map{$row->{'LedgerID'}};
$query = "INSERT INTO pmgr_leases
(`id`, `number`, `lease_type_id`, `unit_id`,
`lease_date`, `movein_date`,
`moveout_date`, `close_date`,
`amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($lid, $row->{'LedgerID'}, $aicur_lease_type_id, $uid,
datefmt($row->{'DateIn'}), datefmt($row->{'DateIn'}),
datefmt($row->{'DateOut'}), datefmt($row->{'DateClosed'}),
$row->{'Rent'})
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_contacts_leases
(`lease_id`, `contact_id`, `type`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($lid, $cid, 'TENANT')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$cid = $tenant_map{$row->{'TenantID'}}{'alt'};
next unless $cid;
$query = "INSERT INTO pmgr_contacts_leases
(`lease_id`, `contact_id`, `type`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($lid, $cid, 'ALTERNATE')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
}
######################################################################
## Security Deposits
$query = "SELECT L.LedgerID, L.UnitID, C.ChargeAmount FROM TenantLedger L INNER JOIN Charges C ON C.LedgerID = L.LedgerID WHERE L.UnitID <> 'POS\$' AND C.ChargeDescription = 'Security Deposit' ORDER BY UnitID";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Security Deposits\n");
foreach $row (@$result) {
my $uid = $unit_map{$row->{'UnitID'}};
$query = "UPDATE pmgr_leases
SET deposit = $row->{'ChargeAmount'}
WHERE `number` = '$row->{'LedgerID'}'";
query($db_handle, $query) || die("Unable to update");
}
######################################################################
######################################################################
######################################################################
######################################################################
######################################################################
######################################################################
##
## TRANSACTIONS
##
######################################################################
## Charges
$query = "SELECT * FROM Charges ORDER BY ChargeID";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Charges\n");
my %charge_type_map = ('Rent' => 2, 'Security Deposit' => 1, 'Late Fee' => 3);
my %charge_map;
foreach $row (@$result) {
$charge_map{$row->{'ChargeID'}} = ++$aicur_charge_id;
my $lid = $ledger_map{$row->{'LedgerID'}};
my $chid = $charge_map{$row->{'ChargeID'}};
$query = "INSERT INTO pmgr_charges
(`id`, `charge_type_id`, `lease_id`,
`charge_date`, `charge_to_date`,
`amount`, `tax`, `total`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($chid, $charge_type_map{$row->{'ChargeDescription'}}, $lid,
datefmt($row->{'ChargeDate'}), datefmt($row->{'EndDate'}),
$row->{'ChargeAmount'}, $row->{'TaxAmount'},
$row->{'ChargeAmount'} + $row->{'TaxAmount'},
undef)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "UPDATE pmgr_charges";
$query .= " SET due_date = DATE_ADD(charge_date, INTERVAL IF(charge_type_id=2,10,0) DAY)";
query($db_handle, $query) || die("Unable to update");
}
######################################################################
## Receipts
$query = "SELECT * FROM Receipts ORDER BY ReceiptNum";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Receipts\n");
my %receipt_map;
foreach $row (@$result) {
$receipt_map{$row->{'ReceiptNum'}} = ++$aicur_receipt_id;
my $lid = $ledger_map{$row->{'LedgerID'}};
my $rid = $receipt_map{$row->{'ReceiptNum'}};
$query = "INSERT INTO pmgr_receipts
(`id`, `stamp`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($rid, datefmt($row->{'ReceiptDate'}), undef)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
}
# $query = "SELECT * FROM Receipts R INNER JOIN Payments P ON P.ReceiptNum = R.ReceiptNum" .
# " WHERE P.PaymentDate <> R.ReceiptDate";
# $result = query($sdbh, $query);
# $nrows = @$result;
# print(" $nrows Mismatches\n");
# foreach $row (@$result) {
# my @keys = qw(PaymentID P.ReceiptNum PaymentDate ReceiptDate);
# print("Payment Date Mismatch:\n");
# print(" ",
# join("\n ", map({sprintf("%-12s => %s", $_, $row->{$_})} @keys)),
# "\n");
# }
######################################################################
## Payments
$query = "SELECT * FROM Payments ORDER BY PaymentID";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Payments\n");
my %payment_map;
foreach $row (@$result) {
$payment_map{$row->{'PaymentID'}} = ++$aicur_payment_id;
my $pid = $payment_map{$row->{'PaymentID'}};
my $rid = $receipt_map{$row->{'ReceiptNum'}};
my $chid = $charge_map{$row->{'ChargeID'}};
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($pid, $rid,
$row->{'PaymentDate'} =~ m%3/25/2009% ? 8 : $row->{'PaymentType'},
$row->{'PaymentAmount'}, undef)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_charges_receipts
(`charge_id`, `receipt_id`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($chid, $rid, $row->{'PaymentAmount'})
)) . ")";
query($db_handle, $query) || die("Unable to insert");
if ($row->{'Memo'}) {
$query =
"UPDATE pmgr_receipts SET `comment` = '$row->{'Memo'}'" .
" WHERE `id` = $rid";
query($db_handle, $query) || die("Unable to update");
}
}
$query = "INSERT INTO pmgr_charges
(`id`, `charge_type_id`, `lease_id`,
`charge_date`, `charge_to_date`,
`amount`, `tax`, `total`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(1000, $charge_type_map{'Security Deposit'}, 17,
'2009-05-05', undef,
10, 0, 10,
'Fake security deposit for testing purposes')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_charges
(`id`, `charge_type_id`, `lease_id`,
`charge_date`, `charge_to_date`,
`amount`, `tax`, `total`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(1001, $charge_type_map{'Rent'}, 17,
'2009-05-01', '2009-05-31',
100, 5, 105,
'Fake charge for testing purposes')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_charges
(`id`, `charge_type_id`, `lease_id`,
`charge_date`, `charge_to_date`,
`amount`, `tax`, `total`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(1002, $charge_type_map{'Late Fee'}, 17,
'2009-05-11', undef,
25, 0, 25,
'Fake late charge for testing purposes')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_receipts
(`id`, `stamp`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(2000, '2009-05-15', 'Fake receipt #1')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3000, 2000, 1, 15, 'Fake receipt #1 payment #1')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3001, 2000, 2, 10, 'Fake receipt #1 payment #2')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3002, 2000, 3, 5, 'Fake receipt #1 payment #3')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_charges_receipts
(`charge_id`, `receipt_id`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(1000, 2000, 10)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_charges_receipts
(`charge_id`, `receipt_id`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(1001, 2000, 20)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_receipts
(`id`, `stamp`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(2100, '2009-05-18', 'Fake receipt #2')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3100, 2100, 5, 30, 'Fake receipt #2 payment #1')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3101, 2100, 6, 20, 'Fake receipt #2 payment #2')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_charges_receipts
(`charge_id`, `receipt_id`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(1001, 2100, 50)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_receipts
(`id`, `stamp`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(2200, '2009-05-22', 'Fake receipt #3')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3200, 2200, 1, 10, 'Fake receipt #3 payment #1')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3201, 2200, 2, 5, 'Fake receipt #3 payment #2')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3202, 2200, 7, 20, 'Fake receipt #3 payment #3')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_payments
(`id`, `receipt_id`, `payment_type_id`, `amount`, `comment`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(3203, 2200, 8, 15, 'Fake receipt #3 payment #4')
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_charges_receipts
(`charge_id`, `receipt_id`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(1001, 2200, 35)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
$query = "INSERT INTO pmgr_charges_receipts
(`charge_id`, `receipt_id`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
(1002, 2200, 15)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
__END__
######################################################################
## Reconciliations
# $query = "SELECT ReceiptNum, SUM(PaymentAmount) AS 'rTot'";
# $query .= " FROM Payments GROUP BY ReceiptNum, ORDER BY ReceiptNum";
$query = "SELECT ChargeID, ReceiptNum";
$query .= " FROM Payments GROUP BY ChargeID, ReceiptNum ORDER BY ChargeID, ReceiptNum";
$result = query($sdbh, $query);
$nrows = @$result;
print(" $nrows Reconciliations\n");
foreach $row (@$result) {
my $chid = $charge_map{$row->{'ChargeID'}};
my $rid = $receipt_map{$row->{'ReceiptNum'}};
$query = "INSERT INTO pmgr_charges_receipts
(`charge_id`, `receipt_id`, `amount`)
VALUES (" .
join(", ", map({defined $_ ? "'$_'" : "NULL"}
($chid, $rid, 0)
)) . ")";
query($db_handle, $query) || die("Unable to insert");
}
$query ="UPDATE pmgr_charges_receipts R
JOIN (SELECT P.receipt_id AS rid,
IF(COALESCE(Ch.total, 0)<SUM(P.amount),
COALESCE(Ch.total, 0),
SUM(P.amount)) AS rtot
FROM pmgr_payments P
LEFT JOIN pmgr_charges_receipts Rl ON Rl.receipt_id = P.receipt_id
LEFT JOIN pmgr_charges Ch ON Ch.id = Rl.charge_id
GROUP BY P.receipt_id) Rx ON Rx.rid = R.receipt_id
SET R.amount = Rx.rtot";
query($db_handle, $query) || die("Unable to update");
$query ="UPDATE pmgr_charges_receipts R
JOIN (SELECT P.receipt_id AS rid, P.total AS total
FROM pmgr_payments P
LEFT JOIN pmgr_charges_receipts Rl ON Rl.receipt_id = P.receipt_id
GROUP BY P.receipt_id) Rx ON Rx.rid = R.receipt_id
SET R.amount = Rx.rtot";
query($db_handle, $query) || die("Unable to update");
# SELECT Rs.receipt_id, Rs.rsum, Ps.psum, rids, pids
# FROM
# (SELECT receipt_id, SUM(R.amount) AS rsum, CAST(GROUP_CONCAT(id) AS CHAR) AS rids
# FROM pmgr_charges_receipts R
# GROUP BY receipt_id) Rs
# LEFT JOIN
# (SELECT receipt_id, SUM(P.amount) AS psum, CAST(GROUP_CONCAT(id) AS CHAR) AS pids
# FROM pmgr_payments P
# GROUP BY receipt_id) Ps ON Ps.receipt_id = Rs.receipt_id
# Disconnect from the database.
$db_handle->disconnect();
View File
View File

Before

Width:  |  Height:  |  Size: 372 B

After

Width:  |  Height:  |  Size: 372 B

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

Before

Width:  |  Height:  |  Size: 201 B

After

Width:  |  Height:  |  Size: 201 B