Odyssey
tools
cumanage
fixtures
bill
sample-loans
generate-loans.php
1
<?php
2
/**
3
* @copyright HomeCu 05/2019
4
*
5
* Generates local DB test loans that work for admin and user.
6
*
7
* Populate your **local database** with random loans for testing. Currently
8
* hard-coded to CRUISECU because that's the only one that works.
9
*
10
* Usage: php generate-local-loan-data.php
11
*
12
* You will be prompted only with "how many loans" and asked to confirm.
13
* When complete, it will give you test login credendials for user apps.
14
* See DB lnappusers for email addresses.
15
*
16
* Change the random data by modifying sample-loans-05-19.csv
17
* (we have a script for that too.)
18
*/
19
20
/** @var string $csv_file, change as needed */
21
$csv_file = __DIR__ .
'/sample-loans-05-19.csv'
;
22
23
/**
24
* @var string - at this point this is the only dev cu that works locally
25
* with loans. Suggest you don't change it.
26
*/
27
$cu =
'CRUISECU'
;
28
29
require_once(
'loan-generator-includes.php'
);
30
31
$sysenv = LoadSystemEnv(
"eforms"
);
32
$dbh = GetDBH($sysenv[
'db'
]);
33
34
/** @var DbLoanCreator $DbObj handles all DB record creation */
35
$DbObj =
new
DbLoanCreator
($dbh);
36
37
/** @var DbLoanCreator $csv_obj converts any CSV into an array for mapping */
38
$CsvObj =
new
CsvToArray
($csv_file);
39
40
/** @var LoanGeneratorMapper $Mapper maps the CSV data to DB data */
41
$Mapper =
new
LoanGeneratorMapper
($cu);
42
43
/**
44
* @var CsvToArray $CsvObj Maps CSV data to table array.
45
* @var DbLoanCreator $DbObj, we will tell it what to write
46
* @var LoanGeneratorMapper $Mapper, we will tell it what to write
47
* @throws Exception
48
* @TODO should really use an interface and force the concrete to have a map() method
49
* @TODO This way we can use it to generate any sample data for any tables
50
*/
51
try
{
52
$obj =
new
LoanDataGenerator
($CsvObj, $DbObj, $Mapper);
53
$obj->WaitForInput();
54
55
}
catch
(Exception $e) {
56
echo
"Exception generating sample loan data: {$e->getMessage()}"
. PHP_EOL;
57
}
58
LoanGeneratorMapper
Definition:
LoanGeneratorMapper.php:14
CsvToArray
Definition:
CsvToArray.php:26
DbLoanCreator
Definition:
DbLoanCreator.php:38
LoanDataGenerator
Definition:
LoanDataGenerator.php:17
Generated by
1.8.15