Add command to archive job order data. #762
This commit is contained in:
parent
8c11ec9e8f
commit
22d4201097
1 changed files with 344 additions and 0 deletions
344
src/Command/GetJobOrderArchiveDataCommand.php
Normal file
344
src/Command/GetJobOrderArchiveDataCommand.php
Normal file
|
|
@ -0,0 +1,344 @@
|
|||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
use PDO;
|
||||
use DateTime;
|
||||
|
||||
class GetJobOrderArchiveDataCommand extends Command
|
||||
{
|
||||
protected $em;
|
||||
protected $project_dir;
|
||||
protected $filesystem;
|
||||
|
||||
public function __construct(EntityManagerInterface $em, KernelInterface $kernel, FileSystem $filesystem)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->project_dir = $kernel->getProjectDir();
|
||||
$this->filesystem = $filesystem;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('joborder:archive')
|
||||
->setDescription('Get job order data to archive.')
|
||||
->setHelp('Get job order data to archive.')
|
||||
->addArgument('cutoff_date', InputArgument::REQUIRED, 'cutoff_date')
|
||||
->addArgument('period', InputArgument::REQUIRED, 'period');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
// get table to back up
|
||||
$period = $input->getArgument('period');
|
||||
$cutoff_date = $input->getArgument('cutoff_date');
|
||||
|
||||
$em = $this->em;
|
||||
|
||||
$db = $em->getConnection();
|
||||
|
||||
// create the archive table
|
||||
$archive_table_name = $this->createArchiveTable($cutoff_date, $period);
|
||||
|
||||
// sql query to retrieve the rows or entries for backup
|
||||
$query_sql = 'SELECT id,
|
||||
customer_id,
|
||||
cvehicle_id,
|
||||
rider_id,
|
||||
date_create,
|
||||
date_schedule,
|
||||
date_fulfill,
|
||||
coordinates,
|
||||
flag_advance,
|
||||
service_type,
|
||||
source,
|
||||
date_cancel,
|
||||
status,
|
||||
delivery_instructions,
|
||||
delivery_address,
|
||||
create_user_id,
|
||||
assign_user_id,
|
||||
date_assign,
|
||||
warranty_class,
|
||||
process_user_id,
|
||||
hub_id,
|
||||
cancel_reason,
|
||||
ref_jo_id,
|
||||
tier1_notes,
|
||||
tier2_notes,
|
||||
mode_of_payment,
|
||||
or_name,
|
||||
landmark,
|
||||
promo_detail,
|
||||
or_num,
|
||||
trade_in_type,
|
||||
flag_rider_rating,
|
||||
flag_coolant,
|
||||
facilitated_hub_id,
|
||||
facilitated_type,
|
||||
coord_long,
|
||||
coord_lat,
|
||||
priority,
|
||||
meta,
|
||||
status_autoassign,
|
||||
first_name,
|
||||
last_name,
|
||||
plate_number,
|
||||
phone_mobile,
|
||||
no_trade_in_reason,
|
||||
will_wait,
|
||||
reason_not_waiting,
|
||||
not_waiting_notes,
|
||||
delivery_status,
|
||||
emergency_type_id,
|
||||
ownership_type_id,
|
||||
cust_location_id,
|
||||
source_of_awareness,
|
||||
remarks,
|
||||
initial_concern,
|
||||
initial_concern_notes,
|
||||
gender,
|
||||
caller_classification,
|
||||
inventory_count
|
||||
FROM job_order
|
||||
WHERE DATE_CREATE < DATE_SUB(:cutoff_date, INTERVAL ' . $period . ' YEAR)';
|
||||
|
||||
$query_stmt = $db->prepare($query_sql);
|
||||
$query_stmt->bindValue('cutoff_date', $cutoff_date, PDO::PARAM_STR);
|
||||
|
||||
$results = $query_stmt->executeQuery();
|
||||
|
||||
$backup_data = [];
|
||||
|
||||
while ($row = $results->fetchAssociative())
|
||||
{
|
||||
$backup_data[] = $this->createBackupData($row);
|
||||
}
|
||||
|
||||
// create the load file for the backup data
|
||||
$this->createLoadDataFileForBackupData($backup_data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function createArchiveTable($str_date, $period)
|
||||
{
|
||||
// form the archive table name <original table name>_archive_<year of data being archived>
|
||||
$modifier = '-' . $period. 'year';
|
||||
|
||||
// convert the date string into DateTime
|
||||
$date = new DateTime($str_date);
|
||||
$year = $date->modify($modifier)->format('Y');
|
||||
|
||||
$archive_table_name = 'job_order_archive_' . $year;
|
||||
|
||||
// create the table if it doesn't exist
|
||||
$db = $this->em->getConnection();
|
||||
|
||||
$create_sql = 'CREATE TABLE IF NOT EXISTS `' . $archive_table_name . '` (
|
||||
`id` int(11) NOT NULL,
|
||||
`customer_id` int(11) DEFAULT NULL,
|
||||
`cvehicle_id` int(11) DEFAULT NULL,
|
||||
`rider_id` int(11) DEFAULT NULL,
|
||||
`date_create` datetime NOT NULL,
|
||||
`date_schedule` datetime NOT NULL,
|
||||
`date_fulfill` datetime DEFAULT NULL,
|
||||
`coordinates` point NOT NULL COMMENT \'(DC2Type:point)\',
|
||||
`flag_advance` tinyint(1) NOT NULL,
|
||||
`service_type` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`source` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`date_cancel` datetime DEFAULT NULL,
|
||||
`status` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`delivery_instructions` longtext COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`delivery_address` longtext COLLATE utf8_unicode_ci NOT NULL,
|
||||
`create_user_id` int(11) DEFAULT NULL,
|
||||
`assign_user_id` int(11) DEFAULT NULL,
|
||||
`date_assign` datetime DEFAULT NULL,
|
||||
`warranty_class` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`process_user_id` int(11) DEFAULT NULL,
|
||||
`hub_id` int(11) DEFAULT NULL,
|
||||
`cancel_reason` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`ref_jo_id` int(11) DEFAULT NULL,
|
||||
`tier1_notes` longtext COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`tier2_notes` longtext COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`mode_of_payment` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`or_name` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`landmark` longtext COLLATE utf8_unicode_ci NOT NULL,
|
||||
`promo_detail` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`or_num` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`trade_in_type` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`flag_rider_rating` tinyint(1) DEFAULT NULL,
|
||||
`flag_coolant` tinyint(1) NOT NULL,
|
||||
`facilitated_hub_id` int(11) DEFAULT NULL,
|
||||
`facilitated_type` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`coord_long` decimal(11,8) NOT NULL,
|
||||
`coord_lat` decimal(11,8) NOT NULL,
|
||||
`priority` int(11) NOT NULL DEFAULT 0,
|
||||
`meta` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
|
||||
`status_autoassign` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`first_name` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`last_name` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`plate_number` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`phone_mobile` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`no_trade_in_reason` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`will_wait` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
|
||||
`reason_not_waiting` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`not_waiting_notes` longtext COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`delivery_status` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`emergency_type_id` int(11) DEFAULT NULL,
|
||||
`ownership_type_id` int(11) DEFAULT NULL,
|
||||
`cust_location_id` int(11) DEFAULT NULL,
|
||||
`source_of_awareness` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`remarks` longtext COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`initial_concern` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`initial_concern_notes` longtext COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`gender` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`caller_classification` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL,
|
||||
`inventory_count` smallint(6) NOT NULL, PRIMARY KEY (`id`))';
|
||||
|
||||
$create_stmt = $db->prepare($create_sql);
|
||||
|
||||
$result = $create_stmt->execute();
|
||||
|
||||
return $archive_table_name;
|
||||
}
|
||||
|
||||
protected function createBackupData($row)
|
||||
{
|
||||
// get job order data
|
||||
// check for nulls. check the ff fields since these can be null: date_fulfill, date_cancel, date_assign, create_user_id,
|
||||
// assign_user_id, proces_user_id, hub_id, rider_id, cancel_reason, ref_jo_id, or_num, trade_in_type,
|
||||
// flag_rider_rating, facilitated_type, facilitated_hub_id, status_autoassign, reason_not_waiting,
|
||||
// not_waiting_notes, no_trade_in_reason, delivery_status, source_of_awareness, remarks, initial_concern,
|
||||
// initial_concern_notes, gender, caller_classifications, emergency_type_id, ownership_type_id, cust_location_id
|
||||
|
||||
$id = $row['id'];
|
||||
$cust_id = $row['customer_id'];
|
||||
$cv_id = $row['cvehicle_id'];
|
||||
|
||||
$rider_id = '\N';
|
||||
if ($row['rider_id'] != NULL)
|
||||
$rider_id = $row]'rider_id'];
|
||||
|
||||
$date_create = $row['date_create'];
|
||||
$date_schedule = $row['date_schedule'];
|
||||
|
||||
$date_fulfill = '\N';
|
||||
if ($row['date_fulfill'] != NULL)
|
||||
$date_fulfill = $row['date_schedule'];
|
||||
|
||||
$coordinates = $row['coordinates'];
|
||||
$flag_advance = $row['flag_advance'];
|
||||
$service_type = $row['service_type'];
|
||||
$source = $row['source'];
|
||||
|
||||
$date_cancel = '\N';
|
||||
if ($row['date_cancel'] != NULL)
|
||||
$date_cancel = $row['date_cancel'];
|
||||
|
||||
$status = $row['status'];
|
||||
$del_instructions = $row['delivery_instructions'];
|
||||
$del_address = $row['delivery_address'];
|
||||
|
||||
$create_user_id = '\N';
|
||||
if ($row['create_user_id'] != NULL)
|
||||
$create_user_id = $row['create_user_id'];
|
||||
|
||||
$assign_user_id = '\N';
|
||||
if ($row['assign_user_id'] != NULL)
|
||||
$assign_user_id = $row['assign_user_id'];
|
||||
|
||||
$date_assign = '\N';
|
||||
if ($row['date_assign'] != NULL)
|
||||
$date_assign = $row['date_assign'];
|
||||
|
||||
$warr_class = $row['warranty_class'];
|
||||
|
||||
$process_user_id = '\N';
|
||||
if ($row['process_user_id'] != NULL)
|
||||
$process_user_id = $row['process_user_id'];
|
||||
|
||||
$hub_id = '\N';
|
||||
if ($row['hub_id'] != NULL)
|
||||
$hub_id = $row['hub_id'];
|
||||
|
||||
$cancel_reason = '\N';
|
||||
if ($row['cancel_reason'] != NULL)
|
||||
$cancel_reason = $row['cancel_reason'];
|
||||
|
||||
$ref_jo_id = '\N';
|
||||
if ($row['ref_jo_id'] != NULL)
|
||||
$ref_jo_id = $row['ref_jo_id'];
|
||||
|
||||
$tier1_notes = $row['tier1_notes'];
|
||||
$tier2_notes = $row['tier2_notes'];
|
||||
$mode_of_payment = $row['mode_of_payment'];
|
||||
$or_name = $row['or_name'];
|
||||
$landmark = $row['landmark'];
|
||||
$promo_details = $row['promo_detail'];
|
||||
|
||||
$or_num = '\N';
|
||||
if ($row['or_num'] != NULL)
|
||||
$or_num = $row['or_num'];
|
||||
|
||||
$trade_in_type = '\N';
|
||||
if ($row['trade_in_type'] != NULL)
|
||||
$trade_in_type = $row['trade_in_type'];
|
||||
|
||||
$flag_rider_rating = '\N';
|
||||
if ($row['flag_rider_rating'] != NULL)
|
||||
$flag_rider_rating = $row['flag_rider_rating'];
|
||||
|
||||
$flag_coolant = $row['flag_coolant'];
|
||||
|
||||
$fac_hub_id = '\N';
|
||||
if ($row['facilitated_hub_id'] != NULL)
|
||||
$fac_hub_id = $row['facilitated_hub_id'];
|
||||
|
||||
$fac_type = '\N';
|
||||
if ($row['facilitated_type'] != NULL)
|
||||
$fac_type = $row['facilitated_type'];
|
||||
|
||||
$coord_long = $row['coord_long'];
|
||||
$coord_lat = $row['coord_lat'];
|
||||
$priority = $row['priority'];
|
||||
$meta = $row['meta'];
|
||||
$status_autoassign = $row['status_autoassign'];
|
||||
$first_name = $row['first_name'];
|
||||
$last_name = $row['last_name'];
|
||||
$plate_number = $row['plate_number'];
|
||||
$phone_mobile = $row['phone_mobile'];
|
||||
$no_trade_in_reason = $row[' no_trade_in_reason'];
|
||||
$will_wait = $row['will_wait'];
|
||||
$reason_not_waiting = $row['reason_not_waiting'];
|
||||
$not_waiting_notes = $row['not_waiting_notes'];
|
||||
$del_status = $row['delivery_status'];
|
||||
$emergency_type_id = $row['emergency_type_id'];
|
||||
$owner_type_id = $row['ownership_type_id'];
|
||||
$cust_location_id = $row['cust_location_id'];
|
||||
$source_of_awareness = $row['source_of_awareness'];
|
||||
$remarks = $row['remarks'];
|
||||
$initial_concern = $row['initial_concern'];
|
||||
$initial_concern_notes = $row['initial_concern_notes'];
|
||||
$gender = $row['gender'];
|
||||
$caller_class = $row['caller_classification'];
|
||||
$inv_count = $row['inventory_count'];
|
||||
|
||||
// check for nulls. check the ff fields since these can be null: date_fulfill, date_cancel, date_assign, create_user_id,
|
||||
// assign_user_id, proces_user_id, hub_id, rider_id, cancel_reason, ref_jo_id, or_num, trade_in_type,
|
||||
// flag_rider_rating, facilitated_type, facilitated_hub_id, status_autoassign, reason_not_waiting,
|
||||
// not_waiting_notes, no_trade_in_reason, delivery_status, source_of_awareness, remarks, initial_concern,
|
||||
// initial_concern_notes, gender, caller_classifications, emergency_type_id, ownership_type_id, cust_location_id
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue