[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[5510] trunk



Revision: 5510
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5510&view=rev
Author:   einhverfr
Date:     2013-01-07 14:42:23 +0000 (Mon, 07 Jan 2013)
Log Message:
-----------
AR/AP batch import from csv added to menu and working in the codebase.  Some csv errors fixed

Modified Paths:
--------------
    trunk/LedgerSMB/Scripts/import_csv.pm
    trunk/sql/Pg-database.sql
    trunk/sql/modules/menu_rebuild.sql

Modified: trunk/LedgerSMB/Scripts/import_csv.pm
===================================================================
--- trunk/LedgerSMB/Scripts/import_csv.pm	2013-01-07 13:40:20 UTC (rev 5509)
+++ trunk/LedgerSMB/Scripts/import_csv.pm	2013-01-07 14:42:23 UTC (rev 5510)
@@ -22,6 +22,8 @@
    gl       =>  ['accno', 'debit', 'credit', 'source', 'memo'],
    ap_multi =>  ['vendor', 'amount', 'account', 'ap', 'description', 
                  'invnumber', 'transdate'],
+   ar_multi =>  ['customer', 'amount', 'account', 'ar', 'description', 
+                 'invnumber', 'transdate'],
    timecard =>  ['employee', 'projectnumber', 'transdate', 'partnumber',
                  'description', 'qty', 'noncharge', 'sellprice', 'allocated',
                 'notes'],
@@ -35,50 +37,15 @@
 our $ar_eca_for_inventory = '00000';
 our $preprocess = {};
 our $postprocess = {};
-our $process = {
-   gl       => sub {
-                   use LedgerSMB::GL;
-                   my ($request, $entries) = @_;
-                   my $form = Form->new();
-                   $form->{reference} = $request->{reference};
-                   $form->{description} = $request->{description};
-                   $form->{transdate} = $request->{transdate};
-                   $form->{rowcount} = 0;
-                   $form->{approved} = '0';
-                   $form->{dbh} = $request->{dbh};
-                   for my $ref (@$entries){
-                       if ($ref->[1] !~ /\d/){
-                          delete $ref->[1];
-                       } else {
-                          print STDERR "debits $ref->[1]\n";
-                          $ref->[1] = $form->parse_amount(
-                                         $request->{_user}, $ref->[1]
-                          );
-                       }
-                       if ($ref->[2] !~ /\d/){
-                          delete $ref->[2];
-                       } else {
-                          print STDERR "credits $ref->[2]\n";
-                          $ref->[2] = $form->parse_amount(
-                                         $request->{_user}, $ref->[2]
-                          );
-                       }
-                       next if !$ref->[1] and !$ref->[2];
-                       for my $col (@{$cols->{$request->{type}}}){
-                           $form->{"${col}_$form->{rowcount}"} = shift @$ref;
-                       }
-                       ++$form->{rowcount};
-                   }
-                   GL->post_transaction($request->{_user}, $form);
-                },
-   ap_multi => sub {
+
+our $aa_multi = sub {
                    use LedgerSMB::AA;
                    use LedgerSMB::Batch;
-                   my ($request, $entries) = @_;
+                   my ($request, $entries, $arap) = @_;
                    my $batch = LedgerSMB::Batch->new({base => $request});
                    $batch->{batch_number} = $request->{reference};
                    $batch->{batch_date} = $request->{transdate};
-                   $batch->{batch_class} = 'ap';
+                   $batch->{batch_class} = $arap;
                    $batch->create(); 
                    # Necessary to test things are found before starting to 
                    # import! -- CT
@@ -107,17 +74,17 @@
                        my $form = Form->new();
                        $form->{dbh} = $request->{dbh};
                        $form->{rowcount} = 1;
+                       $form->{ARAP} = uc($arap);
                        $form->{batch_id} = $batch->{id};
                        $form->{vendornumber} = shift @$ref;
                        $form->{amount_1} = shift @$ref;
                        next if $form->{amount_1} !~ /\d/;
                        $form->{amount_1} = $form->parse_amount(
                               $request->{_user}, $form->{amount_1}); 
-                       $form->{AP_amount_1} = shift @$ref;
-                       $form->{ARAP} = 'AP';
+                       $form->{"$form->{ARAP}_amount_1"} = shift @$ref;
                        $form->{vc} = "vendor";
-                       $form->{arap} = 'ap';
-                       $form->{AP} = shift @$ref;
+                       $form->{arap} = $arap;
+                       $form->{uc($arap)} = shift @$ref;
                        $form->{description_1} = shift @$ref;
                        $form->{invnumber} = shift @$ref;
                        $form->{transdate} = shift @$ref;
@@ -133,7 +100,51 @@
                       
                        AA->post_transaction($request->{_user}, $form);
                    }
+               };
+our $process = {
+   gl       => sub {
+                   use LedgerSMB::GL;
+                   my ($request, $entries) = @_;
+                   my $form = Form->new();
+                   $form->{reference} = $request->{reference};
+                   $form->{description} = $request->{description};
+                   $form->{transdate} = $request->{transdate};
+                   $form->{rowcount} = 0;
+                   $form->{approved} = '0';
+                   $form->{dbh} = $request->{dbh};
+                   for my $ref (@$entries){
+                       if ($ref->[1] !~ /\d/){
+                          delete $ref->[1];
+                       } else {
+                          print STDERR "debits $ref->[1]\n";
+                          $ref->[1] = $form->parse_amount(
+                                         $request->{_user}, $ref->[1]
+                          );
+                       }
+                       if ($ref->[2] !~ /\d/){
+                          delete $ref->[2];
+                       } else {
+                          print STDERR "credits $ref->[2]\n";
+                          $ref->[2] = $form->parse_amount(
+                                         $request->{_user}, $ref->[2]
+                          );
+                       }
+                       next if !$ref->[1] and !$ref->[2];
+                       for my $col (@{$cols->{$request->{type}}}){
+                           $form->{"${col}_$form->{rowcount}"} = shift @$ref;
+                       }
+                       ++$form->{rowcount};
+                   }
+                   GL->post_transaction($request->{_user}, $form);
+                },
+   ar_multi => sub { 
+                   my  ($request, $entries) = @_;
+                   return $aa_multi($request, $entries, 'ar');
                },
+   ap_multi => sub { 
+                   my  ($request, $entries) = @_;
+                   return $aa_multi($request, $entries, 'ap');
+               },
     chart => sub {
                use LedgerSMB::DBObject::Account;
 
@@ -190,6 +201,7 @@
                use LedgerSMB::Timecard;
                my ($request, $entries) = @_;
                my $myconfig = {};
+               my $jc = {};
                for my $entry (@$entries) {
                    my $counter = 0;
                    for my $col (@{$cols->{timecard}}){

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2013-01-07 13:40:20 UTC (rev 5509)
+++ trunk/sql/Pg-database.sql	2013-01-07 14:42:23 UTC (rev 5510)
@@ -2636,6 +2636,8 @@
 101	Generate	98	4
 8	Import	98	3
 114	Inventory Activity	85	2
+11	Import AR Batch	249	3
+13	Import AP Batch	250	3
 206	Batches	205	1
 14	Search	19	2
 12	Add Contact	19	3
@@ -3492,8 +3494,17 @@
 8	module	import_csv.pl	78
 8	action	begin_import	93
 8	type	timecard	94
+11	module	import_csv.pl	95
+13	module	import_csv.pl	152
+11	action	begin_import	172
+13	action	begin_import	173
+11	type	ar_multi	174
+13	type	ap_multi	175
+11	multi	1	176
+13	multi	1	177
 \.
 
+
 --
 
 CREATE TABLE menu_acl (

Modified: trunk/sql/modules/menu_rebuild.sql
===================================================================
--- trunk/sql/modules/menu_rebuild.sql	2013-01-07 13:40:20 UTC (rev 5509)
+++ trunk/sql/modules/menu_rebuild.sql	2013-01-07 14:42:23 UTC (rev 5510)
@@ -21,11 +21,11 @@
 ALTER TABLE public.menu_attribute ALTER COLUMN id DROP DEFAULT;
 ALTER TABLE public.menu_acl ALTER COLUMN id DROP DEFAULT;
 DROP SEQUENCE public.menu_node_id_seq;
-DROP TABLE public.menu_node;
+DROP TABLE public.menu_node CASCADE;
 DROP SEQUENCE public.menu_attribute_id_seq;
 DROP TABLE public.menu_attribute;
 DROP SEQUENCE public.menu_acl_id_seq;
-DROP TABLE public.menu_acl CASCADE;
+DROP TABLE public.menu_acl;
 SET search_path = public, pg_catalog;
 
 SET default_tablespace = '';
@@ -204,11 +204,12 @@
 -- Data for Name: menu_acl; Type: TABLE DATA; Schema: public; Owner: postgres
 --
 
+
 --
 -- Name: menu_acl_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
 --
 
-SELECT pg_catalog.setval('menu_acl_id_seq', 947, true);
+SELECT pg_catalog.setval('menu_acl_id_seq', 949, true);
 
 
 --
@@ -803,6 +804,14 @@
 8	module	import_csv.pl	78
 8	action	begin_import	93
 8	type	timecard	94
+11	module	import_csv.pl	95
+13	module	import_csv.pl	152
+11	action	begin_import	172
+13	action	begin_import	173
+11	type	ar_multi	174
+13	type	ap_multi	175
+11	multi	1	176
+13	multi	1	177
 \.
 
 
@@ -825,6 +834,8 @@
 101	Generate	98	4
 8	Import	98	3
 114	Inventory Activity	85	2
+11	Import AR Batch	249	3
+13	Import AP Batch	250	3
 206	Batches	205	1
 14	Search	19	2
 12	Add Contact	19	3

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.