#!/usr/bin/perl

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

&default;
sub default{

	my @customers = $dbix->resultset('Customer')->search({'me.chainconceptid' => 512, 'customersystem.systemid' => 2, 'customersystem.systemtype' => 0},{
		prefetch => [qw/customersystem/],
		result_class => 'DBIx::Class::ResultClass::HashRefInflator'
	});

	my @ordersystem = $dbix->resultset('OrderInvoiceSystem')->search({'me.id' => 18},{result_class => 'DBIx::Class::ResultClass::HashRefInflator'});
	my $ordersystem = $ordersystem[0];

	show scalar(@customers);
	my $cnt = 0;
	foreach my $cs (@customers){

	#	show $cs;
	
		
		my @customer = $dbix->resultset('Customer')->search({'me.customerid' => $cs->{customerid}},{
			prefetch => [qw/customersystem/],
			result_class => 'DBIx::Class::ResultClass::HashRefInflator'
		});

				

		my $cobj = {
				customerid => $cs->{customerid},
				systemtype => 0,
				systemid => 18,
				systemfiles => $ordersystem->{systemfiles},
				marketid => $cs->{marketid},
				accountingcode => $cs->{accountingcode},
				filecode => $cs->{filecode},
				active => 1
			};

		show $cobj;

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




		$cnt++;


	}

	show $cnt . " records updated";



}


1;