Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 8 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
Sep 16, 2012
f-marais c ce48294
f-marais c 19e833c
Sep 17, 2012
f-marais c 883c5d6
Sep 18, 2012
f-marais c 34b26a4
Sep 25, 2012
f-marais c 17ad717
Sep 26, 2012
f-marais c 513ef73
Oct 11, 2012
f-marais c 096d522
Nov 17, 2012
f-marais c 52f6177
3  .gitignore
@@ -2,7 +2,6 @@
2 2
 *.swp
3 3
 *.log
4 4
 *.db
5  
-*.xls
  5
+*#
6 6
 tmp/
7 7
 db/
8  
-xls/
238  script/xlstodb.pl
@@ -13,11 +13,11 @@ BEGIN
13 13
     use Schema;
14 14
 }
15 15
 
16  
-my $schema = Schema->connect ( sub {X_Db::connect('MIS') });
  16
+my $schema = Schema->connect( sub { X_Db::connect('MIS') } );
17 17
 my %opts;
18  
-getopts('df:', \%opts);  
  18
+getopts( 'df:', \%opts );
19 19
 
20  
-if ($opts{d}) { $schema->deploy({ add_drop_table => 1}); exit 0}
  20
+if ( $opts{d} ) { $schema->deploy( { add_drop_table => 1 } ); exit 0 }
21 21
 
22 22
 sub assign_cols {
23 23
     my ( $sheet, $lkps_ref, $side ) = @_;
@@ -27,16 +27,15 @@ sub assign_cols {
27 27
     for my $col ( $col_min .. $col_max ) {
28 28
         my $val;
29 29
         eval {
30  
-            ($val) = $sheet->get_cell( $row_min, $col )->value 
31  
-                =~ /\s*(.*)\s*/s;
  30
+            ($val) = $sheet->get_cell( $row_min, $col )->value =~ /\s*(.*)\s*/s;
32 31
         };
33 32
         print $@, ",", $col && next if $@;
34 33
         for my $table ( keys %{ $lkps->{$side} } ) {
35 34
             for my $attr ( keys %{ $lkps->{$side}{$table} } ) {
36  
-                if ( $lkps->{$side}{$table}{$attr}{Column} =~m/$val/i ) {
  35
+                if ( $lkps->{$side}{$table}{$attr}{Column} =~ m/$val/i ) {
37 36
                     $lkps->{$side}{$table}{$attr}{Num} = $col;
38  
-                    $ENV{DEBUG} &&
39  
-                        print "Assigning column $col for $side,$table,"
  37
+                    $ENV{DEBUG}
  38
+                      && print "Assigning column $col for $side,$table,"
40 39
                       . "$attr:$val";
41 40
                 }
42 41
             }
@@ -66,7 +65,7 @@ sub assign_val {
66 65
 }
67 66
 
68 67
 my $parser   = Spreadsheet::ParseExcel->new();
69  
-my $workbook = $parser->parse($opts{f});
  68
+my $workbook = $parser->parse( $opts{f} );
70 69
 
71 70
 if ( !defined $workbook ) {
72 71
     die $parser->error(), ".\n";
@@ -78,29 +77,37 @@ sub assign_val {
78 77
 my ( $row_min, $row_max ) = $worksheet->row_range();
79 78
 my ( $col_min, $col_max ) = $worksheet->col_range();
80 79
 
81  
-my $irow=0;
  80
+my $irow = 0;
82 81
 my %col;
83  
-while (my $em_attr=$worksheet->get_cell($irow,0)->value)
84  
-{
85  
-    $col{$em_attr}=$worksheet->get_cell($irow,1)->value;
  82
+while ( my $em_attr = $worksheet->get_cell( $irow, 0 )->value ) {
  83
+    $col{$em_attr} = $worksheet->get_cell( $irow, 1 )->value;
86 84
     $irow++;
87 85
 }
88 86
 
89 87
 #-----------------------------------------------------------------
90 88
 # Delete current entity master and set id for db access
91 89
 #
92  
-$schema->resultset("EntityMaster")->search({ name  => $col{name},
93  
-    version => $col{version}})->delete;
  90
+$schema->resultset("EntityMaster")->search(
  91
+    {
  92
+        name    => $col{name},
  93
+        version => $col{version}
  94
+    }
  95
+)->delete;
94 96
 my ( $sec, $min, $hr, $dd, $mm, $yy ) = (localtime)[ 0, 1, 2, 3, 4, 5 ];
95  
-my $dt= sprintf( "%4.4d-%2.2d-%2.2d %02d:%02d:%02d.000000",
  97
+my $dt = sprintf( "%4.4d-%2.2d-%2.2d %02d:%02d:%02d.000000",
96 98
     1900 + $yy, $mm + 1, $dd, $hr, $min, $sec );
97 99
 
98 100
 $schema->txn_begin;
99 101
 
100  
-my $dbix_em=$schema->resultset('EntityMaster')->create({
101  
-    version=>$col{version},name=>$col{name},
102  
-        uploaded=>$col{uploaded}, author=>$col{author},
103  
-        rel_notes=>$col{rel_notes}});
  102
+my $dbix_em = $schema->resultset('EntityMaster')->create(
  103
+    {
  104
+        version   => $col{version},
  105
+        name      => $col{name},
  106
+        uploaded  => $col{uploaded},
  107
+        author    => $col{author},
  108
+        rel_notes => $col{rel_notes}
  109
+    }
  110
+);
104 111
 
105 112
 $irow++;
106 113
 for my $col ( $col_min .. $col_max ) {
@@ -115,17 +122,17 @@ sub assign_val {
115 122
         (
116 123
             $worksheet->get_cell( $row, $meta_cols{Side} )->value =~
117 124
               /\s*(.*?)\s*$/
118  
-          )[0]
  125
+        )[0]
119 126
       }{
120 127
         (
121 128
             $worksheet->get_cell( $row, $meta_cols{Table} )->value =~
122 129
               /\s*(.*?)\s*$/
123  
-          )[0]
  130
+        )[0]
124 131
       }{
125 132
         (
126 133
             $worksheet->get_cell( $row, $meta_cols{Attribute} )->value =~
127 134
               /\s*(.*?)\s*$/
128  
-          )[0]
  135
+        )[0]
129 136
       }
130 137
       = {
131 138
         'Column' => (
@@ -135,6 +142,7 @@ sub assign_val {
135 142
         'Num' => 0,
136 143
       };
137 144
 }
  145
+
138 146
 #---------------------------------------------
139 147
 # hash used to keep track of max seq number in an entity
140 148
 #
@@ -157,7 +165,7 @@ sub assign_val {
157 165
     die "$this_sheet:No entity" if !exists $tgt->{entity};
158 166
     die "$this_sheet:No Item Name"
159 167
       if exists $tgt->{item}
160  
-          && !exists $tgt->{item}{name};
  168
+      && !exists $tgt->{item}{name};
161 169
 
162 170
     #-------------------------------------------------
163 171
     # Hash used to keep track of current target item
@@ -177,9 +185,13 @@ sub assign_val {
177 185
         if ( !exists $db{$tgt_ent_nm} ) {
178 186
             $ENV{DEBUG} && print "$row:Adding $tgt->{entity}{ds_name}{value}\n";
179 187
             $ENV{DEBUG} && print "Going to insert into entity:$tgt_ent_nm";
180  
-            $db{$tgt_ent_nm}{dbix}=$schema->resultset('Entity')->create({
181  
-                ds_name=>$tgt_ent_nm,ds_no=>$tgt->{entity}{ds_no}{value},
182  
-                em_id=>$dbix_em->id});
  188
+            $db{$tgt_ent_nm}{dbix} = $schema->resultset('Entity')->create(
  189
+                {
  190
+                    ds_name => $tgt_ent_nm,
  191
+                    ds_no   => $tgt->{entity}{ds_no}{value},
  192
+                    em_id   => $dbix_em->id
  193
+                }
  194
+            );
183 195
             $db{$tgt_ent_nm}{seq} = 1;
184 196
         }
185 197
         $tgt_ent_nm = $tgt->{entity}{ds_name}{value};
@@ -187,35 +199,41 @@ sub assign_val {
187 199
             next if $attr eq 'ds_name';
188 200
             my $attr_val = $tgt->{entity}{$attr}{value};
189 201
             next unless defined $attr_val;
190  
-            $ENV{DEBUG} && print "Updating entity $tgt_ent_nm:$attr"
191  
-                . " with $attr_val\n";
192  
-            $db{$tgt_ent_nm}{dbix}->$attr($attr_val) &&
193  
-            $db{$tgt_ent_nm}{dbix}->update if defined $attr_val;
  202
+            $ENV{DEBUG}
  203
+              && print "Updating entity $tgt_ent_nm:$attr"
  204
+              . " with $attr_val\n";
  205
+            $db{$tgt_ent_nm}{dbix}->$attr($attr_val)
  206
+              && $db{$tgt_ent_nm}{dbix}->update
  207
+              if defined $attr_val;
194 208
         }
195  
-        my ( $tgt_itm_nm,  $src_itm_id, $src_itm_nm );
196  
-        if ( exists $tgt->{item}
197  
-            && defined $tgt->{item}{name}{value} 
  209
+        my ( $tgt_itm_nm, $src_itm_id, $src_itm_nm );
  210
+        if (   exists $tgt->{item}
  211
+            && defined $tgt->{item}{name}{value}
198 212
             && $tgt->{item}{name}{value} !~ /^\s*$/ )
199 213
         {
200 214
             $tgt_itm_nm = $tgt->{item}{name}{value};
201 215
             $tgt_itm_nm =~ s/[^[:print:]]+/ /;
202 216
             print "Inserting item $tgt_itm_nm in $tgt_ent_nm\n" if $ENV{DEBUG};
203  
-            my $dbix_it=$schema->resultset('Item')->create({
204  
-                name=>$tgt_itm_nm,et_id=> $db{$tgt_ent_nm}{dbix}->id,
205  
-                seq=> $db{$tgt_ent_nm}{seq}++ });
206  
-            $db{$tgt_ent_nm}{items}{$tgt_itm_nm}{id} =$dbix_it->id;
  217
+            my $dbix_it = $schema->resultset('Item')->create(
  218
+                {
  219
+                    name  => $tgt_itm_nm,
  220
+                    et_id => $db{$tgt_ent_nm}{dbix}->id,
  221
+                    seq   => $db{$tgt_ent_nm}{seq}++
  222
+                }
  223
+            );
  224
+            $db{$tgt_ent_nm}{items}{$tgt_itm_nm}{id} = $dbix_it->id;
207 225
             for my $attr ( keys %{ $tgt->{item} } ) {
208 226
                 next if $attr eq 'name';
209 227
                 my $attr_val = $tgt->{item}{$attr}{value};
210 228
                 print "Updating item $tgt_itm_nm:$attr with $attr_val\n"
211 229
                   if $ENV{DEBUG} && defined $attr_val;
212  
-                $dbix_it->$attr($attr_val) &&
213  
-                     $dbix_it->update if defined $attr_val;
  230
+                $dbix_it->$attr($attr_val)
  231
+                  && $dbix_it->update
  232
+                  if defined $attr_val;
214 233
             }
215 234
         }
216 235
     }
217 236
 }
218  
-
219 237
 print "Looking at: Sources\n";
220 238
 for my $this_sheet (@lkp_sheets) {
221 239
     print $this_sheet, "\n";
@@ -236,79 +254,101 @@ sub assign_val {
236 254
     for my $row ( $row_min + 1 .. $row_max ) {
237 255
         assign_val( $row, $worksheet, \$wksht_lkps, 'tgt' );
238 256
         assign_val( $row, $worksheet, \$wksht_lkps, 'src' );
239  
-        my ( $tgt_itm_nm, $tgt_itm_id, $dbix_src_itm,$src_itm_nm );
  257
+        my ( $tgt_itm_nm, $tgt_itm_id, $dbix_src_itm );
240 258
 
241 259
         #----------------------------------------------
242 260
         # Only look at this row if we have a tgt
243  
-        next unless (exists $curr_itm{ent_nm} ||$tgt->{entity}{ds_name}{value})
244  
-        && (exists $curr_itm{itm_nm} || $tgt->{item}{name}{value});
  261
+        next
  262
+          unless ( exists $curr_itm{ent_nm} || $tgt->{entity}{ds_name}{value} )
  263
+          && ( exists $curr_itm{itm_nm} || $tgt->{item}{name}{value} );
245 264
 
246  
-        if ( $tgt->{entity}{ds_name}{value} 
247  
-        && $tgt->{item}{name}{value}) {
  265
+        if (   $tgt->{entity}{ds_name}{value}
  266
+            && $tgt->{item}{name}{value} )
  267
+        {
248 268
             $curr_itm{ent_nm} = $tgt->{entity}{ds_name}{value};
249  
-            $curr_itm{itm_nm}=$tgt->{item}{name}{value};
  269
+            $curr_itm{itm_nm} = $tgt->{item}{name}{value};
250 270
         }
251 271
         $ENV{DEBUG} && print "Current tgt ent: $curr_itm{ent_nm}
252 272
             item: $curr_itm{itm_nm}\n";
  273
+
253 274
         #-----------------------------------------------------
254  
-        next unless $db{$curr_itm{ent_nm}}{dbix}->id;
255  
-        next unless $src->{entity}{ds_name}{value}
256  
-            && $src->{entity}{ds_name}{value} !~m{n/a}ims;
257  
-        my $src_ent_nm = $src->{entity}{ds_name}{value};
258  
-        my $dbix_src_et;
259  
-        if ( !exists $db{$src_ent_nm}) {
260  
-            $ENV{DEBUG} && print "Inserting source entity $src_ent_nm\n";
261  
-            $dbix_src_et=$schema->resultset('Entity')->create({
262  
-            em_id=>$dbix_em->id,ds_name=>$src_ent_nm});
263  
-            $db{$src_ent_nm}{dbix}  = $dbix_src_et;
264  
-            $db{$src_ent_nm}{seq} = 1;
265  
-        }
  275
+        next unless $db{ $curr_itm{ent_nm} }{dbix}->id;
  276
+        next
  277
+          unless $src->{entity}{ds_name}{value}
  278
+          && $src->{entity}{ds_name}{value} !~ m{n/a}ims;
266 279
 
267 280
         #-------------------------------------------------
268 281
         # Tgt and src items
269  
-        next unless $src->{item}{name}{value}
270  
-            && $src->{item}{name}{value} !~m{n/a}ims;
271  
-        $ENV{DEBUG} && print "Source item:",$src->{item}{name}{value},"\n";
272  
-        $src_itm_nm = $src->{item}{name}{value};
273  
-        for my $itm ($src_itm_nm=~/\s*([A-Za-z0-9_ .]+)\s*/gms)
274  
-        {
275  
-            if ( !exists $db{$src_ent_nm}{items}{$itm}) {
276  
-                $ENV{DEBUG} && print "Inserting item $src_itm_nm\n";
277  
-                my $dbix_src_itm=$schema->resultset('Item')->create({
278  
-                    name=>$itm,et_id=> $db{$src_ent_nm}{dbix}->id,
279  
-                    seq=> $db{$src_ent_nm}{seq}++ });
280  
-                die "$itm item in $src_ent_nm "
281  
-                    . "did not produce id" unless $dbix_src_itm;
  282
+        next
  283
+          unless $src->{item}{name}{value}
  284
+          && $src->{item}{name}{value} !~ m{n/a}ims;
  285
+        $ENV{DEBUG} && print "Source item:", $src->{item}{name}{value}, "\n";
  286
+        my @src_ents =
  287
+          ( $src->{entity}{ds_name}{value} =~ /\s*([A-Za-z0-9_.]+)\s*/gms );
  288
+        my $src_itm_nm = $src->{item}{name}{value};
  289
+        my $enti       = 0;
  290
+        for my $itm ( $src_itm_nm =~ /\s*([A-Za-z0-9_.]+)\s*/gms ) {
  291
+            my $dbix_src_et;
  292
+            my $src_ent_nm = $src_ents[$enti];
  293
+            if ( !exists $db{$src_ent_nm} ) {
  294
+                $ENV{DEBUG} && print "Inserting source entity $src_ent_nm\n";
  295
+                $dbix_src_et =
  296
+                  $schema->resultset('Entity')
  297
+                  ->create( { em_id => $dbix_em->id, ds_name => $src_ent_nm } );
  298
+                $db{$src_ent_nm}{dbix} = $dbix_src_et;
  299
+                $db{$src_ent_nm}{seq}  = 1;
  300
+            }
  301
+
  302
+            $enti++ unless $enti == scalar @src_ents - 1;
  303
+            if ( !exists $db{$src_ent_nm}{items}{$itm} ) {
  304
+                $ENV{DEBUG} && print "Inserting source item $src_itm_nm\n";
  305
+                my $dbix_src_itm = $schema->resultset('Item')->create(
  306
+                    {
  307
+                        name  => $itm,
  308
+                        et_id => $db{$src_ent_nm}{dbix}->id,
  309
+                        seq   => $db{$src_ent_nm}{seq}++
  310
+                    }
  311
+                );
  312
+                die "$itm item in $src_ent_nm " . "did not produce id"
  313
+                  unless $dbix_src_itm;
282 314
                 for my $attr ( keys %{ $src->{item} } ) {
283 315
                     next if $attr eq 'name' || $attr eq 'bus_rule';
284  
-                    $dbix_src_itm->$attr($src->{item}{$attr}{value})
285  
-                    && $dbix_src_itm->update
286  
-                        if defined $src->{item}{$attr}{value};
  316
+                    $dbix_src_itm->$attr( $src->{item}{$attr}{value} )
  317
+                      && $dbix_src_itm->update
  318
+                      if defined $src->{item}{$attr}{value};
287 319
                 }
288  
-                $db{$src_ent_nm}{items}{$itm}{id}  = $dbix_src_itm->id;
  320
+                $db{$src_ent_nm}{items}{$itm}{id} = $dbix_src_itm->id;
289 321
             }
290  
-            my $dbix_i2i_itm=$schema->resultset('I2i')->create({
291  
-                tgt_id=>$db{$curr_itm{ent_nm}}{items}{$curr_itm{itm_nm}}{id},
292  
-                src_id=>$db{$src_ent_nm}{items}{$itm}{id}});
293  
-            $ENV{DEBUG} && print "Inserting item $src_itm_nm\n
  322
+            my $dbix_i2i_itm = $schema->resultset('I2i')->create(
  323
+                {
  324
+                    tgt_id =>
  325
+                      $db{ $curr_itm{ent_nm} }{items}{ $curr_itm{itm_nm} }{id},
  326
+                    src_id => $db{$src_ent_nm}{items}{$itm}{id}
  327
+                }
  328
+            );
  329
+            $ENV{DEBUG} && print "2Inserting source item $src_itm_nm\n
294 330
                     for target item $curr_itm{itm_nm} and ent: 
295 331
                     $curr_itm{ent_nm}";
296 332
         }
297 333
     }
298 334
 }
299 335
 
300  
-my $cdrs = $schema->resultset('EntityMaster')->search({name=>$col{name}});
  336
+my $cdrs = $schema->resultset('EntityMaster')->search( { name => $col{name} } );
301 337
 
302  
-$cdrs->update({max_version=>0});
303  
-my $rs = $cdrs->search({
304  
-    version => {
305  
-        '=' => $cdrs->search({ name=>$col{name}})
306  
-            ->get_column('version')->max_rs->as_query } });
  338
+$cdrs->update( { max_version => 0 } );
  339
+my $rs = $cdrs->search(
  340
+    {
  341
+        version => {
  342
+            '=' => $cdrs->search( { name => $col{name} } )
  343
+              ->get_column('version')->max_rs->as_query
  344
+        }
  345
+    }
  346
+);
307 347
 
308  
-$rs->update({max_version=>1});
  348
+$rs->update( { max_version => 1 } );
309 349
 
310 350
 $schema->txn_commit;
311  
-system  'sync';
  351
+system 'sync';
312 352
 __END__
313 353
 
314 354
 =head1 Rules
@@ -366,7 +406,8 @@ =head1 Items per entity master
366 406
 select name, version, max_version from entity_master;
367 407
 
368 408
 select a.* from item a, entity b
369  
-where a.et_id=b.et_id and b.name like '%MI_STB_REWARD_ALLOCATION_T%'
  409
+where a.et_id=b.et_id and b.ds_name like '%RWRD_ALLOC_A%'
  410
+and a.name='SUFF_CREDITS_IND'
370 411
 order by a.seq;
371 412
 
372 413
 SELECT me.scope, me.type, me.description 
@@ -386,4 +427,23 @@ =head1 Items per entity master
386 427
 ) 
387 428
 AND name = 'FEWR dfsdfs';
388 429
 
  430
+select  c.name em_nm,b.ds_name tgt_ent_nm,b.type tgt_ent_type,
  431
+        a.name tgt_itm_nm, 
  432
+        ifnull(f.src_itm_nm,' ') src_itm_nm, 
  433
+        ifnull(f.src_ent_nm,' ') src_ent_nm,
  434
+        a.deflt, a.seq
  435
+    from item a join entity b on a.et_id=b.et_id
  436
+    join entity_master c on b.em_id=c.em_id
  437
+    left join (select c.tgt_id,d.name src_itm_nm,
  438
+        d.type src_itm_type, d.precision src_itm_precision,
  439
+        e.ds_name src_ent_nm,e.type src_ent_type,
  440
+        d.seq src_seq
  441
+        from i2i c, item d, entity e
  442
+        where c.src_id=d.it_id and d.et_id=e.et_id) f
  443
+    on a.it_id=f.tgt_id
  444
+    where c.max_version=1
  445
+    -- and b.ds_name like '%BASE_ACCT_A%'
  446
+    and a.name='TOT_MONTHLY_FUEL_PURCHASE'
  447
+    order by a.seq,f.src_seq;
  448
+
389 449
 update entity_master set name = 'CBS Rewards' ;

No commit comments for this range

Something went wrong with that request. Please try again.