#!/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;

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 @c = $dbix->resultset('EmailNotification')->search({
		actiontype => 'EMAIL_ON_ADD_BP_MIGRATE'
	},{
		prefetch=>[qw//],
		result_class=>'DBIx::Class::ResultClass::HashRefInflator'
	});

	my $rtemplate = q~
<P>New Branded Procurement (BP) account(s) have been added. The user name and passwords are listed below.</P><P><BR></P>

<table width="100%" border="1">
<thead>
	<tr>
		<th>COMPANY</th>
		<th>ACCT NAME</th>
		<th>STORE#</th>
		<th>WHS</th>
		<th>USERNAME</th>
		<th>PASSWORD</th>	
	</tr>
</thead>
<tbody>
<% foreach my $r (@$customers){ %>
	<tr>
		<td><%= $r->{chaingrp}->{chaingroupname} %></td>
		<td><%= $r->{unitname} %></td>
		<td><%= $r->{customerunitnumber} %></td>
		<td><%= $r->{warehouse}->{siteshortname} %></td>
		<td><%= $r->{user} %></td>
		<td><%= $r->{password} ? $r->{password} : $r->{user} %></td>
	</tr>
<% } %>	
</tbody>
</table>



<P>If you have any questions or need to be removed from the distribution list, please contact:</P><P>Jenisse Hernandez<BR>Direct: 847.252.1967<BR><A HREF="MAILTO:matt.kot@dmadelivers.com">matt.kot@dmadelivers.com</A><BR></P><DIV><BR></DIV>
~;


	foreach my $r (@c){
		$dbix->resultset('EmailNotification')->search({
			emailnotificationid => $r->{emailnotificationid}
		})->update({body => $rtemplate});

	}

}