#!/usr/bin/perl

# $ENV{DBIC_TRACE}=1;
use strict;
use Data::Show;
use lib '/home/sites/clm.dmadelivers.com/www/clmapp/lib';
use CLMApp::Schema;
my $dbix = CLMApp::Schema->connect("dbi:mysql:host=rds1.dmadelivers.com;db=dmaclm", 'dmaclm', '3lUz1OV2!',{unsafe=>1,RaiseError=>0,PrintError=>1});


# &default;
&fix_missing;
sub fix_missing{

	my @cs = $dbix->resultset('Customer')->search({ 
		statusid => 1,
		comments => {'=' => 'NEW'},
		# customerid => 1060791
	},{
		result_class=>'DBIx::Class::ResultClass::HashRefInflator',
	});

	# show @cs;
	show scalar(@cs);

	foreach my $cs (@cs){

		my $cobj = {customerid => $cs->{customerid}, active => 1, deleted => 0, created => $cs->{setupdate}, updated => $cs->{setupdate}, createdby => $cs->{lastupdatedbyid}, updatedby => $cs->{lastupdatedbyid}, customercommentdescription => $cs->{comments} };

		$dbix->resultset('CustomerComment')->create($cobj);		

	}


}

sub default{

# 1060791
	my @cs = $dbix->resultset('Customer')->search({ 
		statusid => 1,
		comments => {'!=' => ''},
		# customerid => 1060791
	},{
		result_class=>'DBIx::Class::ResultClass::HashRefInflator',
	});

# show \@cs;
	foreach my $cs (@cs){
		my $cobj = {
			customercommentdescription => $cs->{comments},
			customerid => $cs->{customerid},
			active => 1,
			deleted => 0,
			createdby => $cs->{lastupdatedbyid},
			created => $cs->{lastchangeddate},
			updatedby => $cs->{lastupdatedbyid},
			updated => $cs->{lastchangeddate},			
		};
		# show $cobj;
		next unless $cs->{customerid} && $cs->{comments};
		$dbix->resultset('CustomerComment')->create($cobj);

	}



}

1;
