Merge branch 'master' of github.com:kivitendo/kivitendo-erp
authorJan Büren <jan@kivitendo-premium.de>
Tue, 16 Apr 2013 08:36:13 +0000 (10:36 +0200)
committerJan Büren <jan@kivitendo-premium.de>
Tue, 16 Apr 2013 08:36:13 +0000 (10:36 +0200)
SL/CP.pm
SL/Controller/CsvImport/Base.pm
SL/Controller/CsvImport/CustomerVendor.pm
SL/DB/Invoice.pm
bin/mozilla/ic.pl
bin/mozilla/io.pl
locale/de/all
sql/Pg-upgrade2/acc_trans_booleans_not_null.sql [new file with mode: 0644]
templates/webpages/csv_import/_form_customers_vendors.html
templates/webpages/rp/balance_sheet.html

index 5786bf8..18673c2 100644 (file)
--- a/SL/CP.pm
+++ b/SL/CP.pm
@@ -269,20 +269,20 @@ sub process_payment {
 
       # add AR/AP
       $query =
-        qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount) | .
-        qq|VALUES (?, ?, ?, ?)|;
+        qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, chart_link, taxkey, tax_id) | .
+        qq|VALUES (?, ?, ?, ?, (SELECT link FROM chart WHERE id=?), 0, (SELECT id FROM tax WHERE taxkey=0 LIMIT 1))|;
       do_query($form, $dbh, $query, $form->{"id_$i"}, $id,
-               conv_date($form->{datepaid}), $amount * $ml);
+               conv_date($form->{datepaid}), $amount * $ml, $id);
 
       # add payment
       $query =
         qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, | .
-        qq|                       source, memo) | .
-        qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
+        qq|                       source, memo, chart_link, taxkey, tax_id) | .
+        qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, (SELECT link FROM chart WHERE accno=?), 0, (SELECT id FROM tax WHERE taxkey=0 LIMIT 1))|;
       my @values = (conv_i($form->{"id_$i"}), $paymentaccno,
                     conv_date($form->{datepaid}),
                     $form->{"paid_$i"} * $ml * -1, $form->{source},
-                    $form->{memo});
+                    $form->{memo}, $paymentaccno);
       do_query($form, $dbh, $query, @values);
 
       # add exchangerate difference if currency ne defaultcurrency
@@ -293,11 +293,11 @@ sub process_payment {
         # exchangerate difference
         $query =
           qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, amount, | .
-          qq|                       cleared, fx_transaction) | .
-          qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?)|;
+          qq|                       cleared, fx_transaction, chart_link, taxkey, tax_id) | .
+          qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, (SELECT link FROM chart WHERE accno = ?), 0, (SELECT id FROM tax WHERE taxkey=0 LIMIT 1))|;
         @values = (conv_i($form->{"id_$i"}), $paymentaccno,
                    conv_date($form->{datepaid}), ($amount * $ml * -1), '0',
-                   '1');
+                   '1', $paymentaccno);
         do_query($form, $dbh, $query, @values);
 
         # gain/loss
@@ -309,11 +309,11 @@ sub process_payment {
           my $accno_id = ($amount < 0) ? $fxgain_accno_id : $fxloss_accno_id;
           $query =
             qq|INSERT INTO acc_trans (trans_id, chart_id, transdate, | .
-            qq|                       amount, cleared, fx_transaction) | .
-            qq|VALUES (?, ?, ?, ?, ?, ?)|;
+            qq|                       amount, cleared, fx_transaction, chart_link, taxkey, tax_id) | .
+            qq|VALUES (?, ?, ?, ?, ?, ?, (SELECT link FROM chart WHERE id=?), 0, (SELECT id FROM tax WHERE taxkey=0 LIMIT 1))|;
           @values = (conv_i($form->{"id_$i"}), $accno_id,
                      conv_date($form->{datepaid}), $amount * $ml * -1, '0',
-                     '1');
+                     '1', $accno_id);
           do_query($form, $dbh, $query, @values);
         }
       }
index fa3e4f4..e7889d7 100644 (file)
@@ -422,5 +422,20 @@ sub fix_field_lengths {
   }
 }
 
-1;
+sub clean_fields {
+  my ($self, $illegal_chars, $object, @fields) = @_;
+
+  my @cleaned_fields;
+  foreach my $field (grep { $object->can($_) } @fields) {
+    my $value = $object->$field;
+
+    next unless defined($value) && ($value =~ s/$illegal_chars/ /g);
+
+    $object->$field($value);
+    push @cleaned_fields, $field;
+  }
+
+  return @cleaned_fields;
+}
 
+1;
index 757c52c..f8774dc 100644 (file)
@@ -49,8 +49,11 @@ sub check_objects {
 
   $self->controller->track_progress(phase => 'building data', progress => 0);
 
-  my $numbercolumn  = $self->controller->profile->get('table') . "number";
-  my %vcs_by_number = map { ( $_->$numbercolumn => 1 ) } @{ $self->existing_objects };
+  my $vc            = $self->controller->profile->get('table');
+  my $update_policy = $self->controller->profile->get('update_policy') || 'update_existing';
+  my $numbercolumn  = "${vc}number";
+  my %vcs_by_number = map { ( $_->$numbercolumn => $_ ) } @{ $self->existing_objects };
+  my $methods       = $self->controller->headers->{methods};
 
   my $i;
   my $num_data = scalar @{ $self->controller->data };
@@ -66,10 +69,29 @@ sub check_objects {
 
     next if @{ $entry->{errors} };
 
-    if ($vcs_by_number{ $object->$numbercolumn }) {
-      $entry->{object}->$numbercolumn('####');
-    } else {
+    my @cleaned_fields = $self->clean_fields(qr{[\r\n]}, $object, qw(name department_1 department_2 street zipcode city country contact phone fax homepage email cc bcc
+                                                                     taxnumber account_number bank_code bank username greeting));
+
+    push @{ $entry->{information} }, $::locale->text('Illegal characters have been removed from the following fields: #1', join(', ', @cleaned_fields))
+      if @cleaned_fields;
+
+    my $existing_vc = $vcs_by_number{ $object->$numbercolumn };
+    if (!$existing_vc) {
       $vcs_by_number{ $object->$numbercolumn } = $object;
+
+    } elsif ($update_policy eq 'skip') {
+      push(@{$entry->{errors}}, $::locale->text('Skipping due to existing entry in database'));
+
+    } elsif ($update_policy eq 'update_existing') {
+      # Update existing customer/vendor records.
+      $entry->{object_to_save} = $existing_vc;
+
+      $existing_vc->$_( $entry->{object}->$_ ) for @{ $methods };
+
+      push @{ $entry->{information} }, $::locale->text('Updating existing entry in database');
+
+    } else {
+      $object->$numbercolumn('####');
     }
   } continue {
     $i++;
@@ -139,7 +161,7 @@ sub check_business {
   my $object = $entry->{object};
 
   # Check whether or not business ID is valid.
-  if ($object->business_id && !$self->businesss_by->{id}->{ $object->business_id }) {
+  if ($object->business_id && !$self->businesses_by->{id}->{ $object->business_id }) {
     push @{ $entry->{errors} }, $::locale->text('Error: Invalid business');
     return 0;
   }
index 77d6769..861c92a 100644 (file)
@@ -90,7 +90,7 @@ sub new_from {
   croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) =~ m/^ SL::DB:: (?: Order | DeliveryOrder ) $/x;
   croak("Cannot create invoices for purchase records")           unless $source->customer_id;
 
-  my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_term->terms_netto : 0;
+  my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms->terms_netto : 0;
 
   my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes curr salesman_id cusordnumber ordnumber quonumber
                                                 department_id cp_id language_id payment_id delivery_customer_id delivery_vendor_id taxzone_id shipto_id
index b1540e1..c0841cf 100644 (file)
@@ -1761,12 +1761,14 @@ sub update {
 
   # parse pricegroups. and no, don't rely on check_form for this...
   map { $form->{"price_$_"} = $form->parse_amount(\%myconfig, $form->{"price_$_"}) } 1 .. $form->{price_rows};
+  $form->{sellprice} = $form->parse_amount(\%myconfig, $form->{sellprice});
 
   # same for makemodel lastcosts
   # but parse_amount not necessary for assembly component lastcosts
   unless ($form->{item} eq "assembly") {
     map { $form->{"lastcost_$_"} = $form->parse_amount(\%myconfig, $form->{"lastcost_$_"}) } 1 .. $form->{"makemodel_rows"};
   };
+  $form->{listprice} = $form->parse_amount(\%myconfig, $form->{listprice});
 
   if ($form->{item} eq "assembly") {
     my $i = $form->{assembly_rows};
index 4ec2729..515d08e 100644 (file)
@@ -571,7 +571,6 @@ sub item_selected {
   map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
     qw(sellprice listprice weight);
 
-  $form->{sellprice} += ($form->{"sellprice_$i"} * $form->{"qty_$i"});
   $form->{weight}    += ($form->{"weight_$i"} * $form->{"qty_$i"});
 
   if ($form->{"not_discountable_$i"}) {
index dbfe48d..fc46978 100644 (file)
@@ -854,6 +854,7 @@ $self->{texts} = {
   'Execution type'              => 'Ausführungsart',
   'Existing Buchungsgruppen'    => 'Existierende Buchungsgruppen',
   'Existing Datasets'           => 'Existierende Datenbanken',
+  'Existing customers/vendors with same customer/vendor number' => 'Existierende Kunden/Lieferanten mit derselben Kunden-/Lieferantennummer',
   'Existing file on server'     => 'Auf dem Server existierende Datei',
   'Existing pending follow-ups for this item' => 'Noch nicht erledigte Wiedervorlagen f&uuml;r dieses Dokument',
   'Existing profiles'           => 'Existierende Profile',
@@ -992,6 +993,7 @@ $self->{texts} = {
   'If you want to change any of these parameters then press the &quot;Back&quot; button, edit the file &quot;config/kivitendo.conf&quot; and login into the admin module again.' => 'Wenn Sie einen der Parameter &auml;ndern wollen, so dr&uuml;cken Sie auf den &quot;Zur&uuml;ck&quot;-Button, bearbeiten Sie die Datei &quot;config/kivitendo.conf&quot;, und melden Sie sich erneut im Administrationsbereich an.',
   'If you want to delete such a dataset you have to edit the user(s) that are using the dataset in question and have them use another dataset.' => 'Wenn Sie eine solche Datenbank l&ouml;schen wollen, so m&uuml;ssen Sie zuerst die Benutzer bearbeiten, die die fragliche Datenbank benutzen, und sie so &auml;ndern, dass sie eine andere Datenbank benutzen.',
   'If you want to set up the authentication database yourself then log in to the administration panel. kivitendo will then create the database and tables for you.' => 'Wenn Sie die Authentifizierungs-Datenbank selber einrichten wollen, so melden Sie sich im Administrationsbereich an. kivitendo wird dann die Datenbank und die erforderlichen Tabellen für Sie anlegen.',
+  'Illegal characters have been removed from the following fields: #1' => 'Ungültige Zeichen wurden aus den folgenden Feldern entfernt: #1',
   'Image'                       => 'Grafik',
   'Import'                      => 'Import',
   'Import CSV'                  => 'CSV-Import',
@@ -1026,6 +1028,7 @@ $self->{texts} = {
   'Increase'                    => 'Erhöhen',
   'Individual Items'            => 'Einzelteile',
   'Information'                 => 'Information',
+  'Insert with new customer/vendor number' => 'Mit neuer Kunden-/Lieferantennummer anlegen',
   'Insert with new part number' => 'Mit neuer Artikelnummer einfügen',
   'Interest'                    => 'Zinsen',
   'Interest Rate'               => 'Zinssatz',
@@ -1784,7 +1787,7 @@ $self->{texts} = {
   'Single values in item mode, cumulated values in invoice mode' => 'Einzelwerte im Artikelmodus, kumulierte Werte im Rechnungsmodus',
   'Skip'                        => 'Überspringen',
   'Skip entry'                  => 'Eintrag überspringen',
-  'Skipping due to existing entry in database' => 'Übersprungen, wegen existierender Artikelnummer',
+  'Skipping due to existing entry in database' => 'Wegen existierendem Eintrag mit selber Nummer übersprungen',
   'Skonto'                      => 'Skonto',
   'Skonto Terms'                => 'Zahlungsziel Skonto',
   'Sold'                        => 'Verkauft',
@@ -2211,8 +2214,10 @@ $self->{texts} = {
   'Update complete'             => 'Update beendet.',
   'Update prices'               => 'Preise aktualisieren',
   'Update prices of existing entries' => 'Preise von vorhandenen Artikeln aktualisieren',
+  'Update properties of existing entries' => 'Eigenschaften von existierenden Einträgen aktualisieren',
   'Update?'                     => 'Aktualisieren?',
   'Updated'                     => 'Erneuert am',
+  'Updating existing entry in database' => 'Existierenden Eintrag in Datenbank aktualisieren',
   'Updating prices of existing entry in database' => 'Preis des Eintrags in der Datenbank wird aktualisiert',
   'Uploaded on #1, size #2 kB'  => 'Am #1 hochgeladen, Größe #2 kB',
   'Use As New'                  => 'Als neu verwenden',
diff --git a/sql/Pg-upgrade2/acc_trans_booleans_not_null.sql b/sql/Pg-upgrade2/acc_trans_booleans_not_null.sql
new file mode 100644 (file)
index 0000000..983e53d
--- /dev/null
@@ -0,0 +1,14 @@
+-- @tag: acc_trans_booleans_not_null
+-- @description: Alte acc_trans boolean-Einträge mit NULL-Werten auf false setzen
+-- @depends: release_3_0_0
+-- @charset: utf-8
+
+UPDATE acc_trans SET cleared        = 'f' where cleared        IS NULL;
+UPDATE acc_trans SET ob_transaction = 'f' where ob_transaction IS NULL;
+UPDATE acc_trans SET cb_transaction = 'f' where cb_transaction IS NULL;
+UPDATE acc_trans SET fx_transaction = 'f' where fx_transaction IS NULL;
+
+ALTER TABLE acc_trans ALTER cleared        SET NOT NULL;
+ALTER TABLE acc_trans ALTER ob_transaction SET NOT NULL;
+ALTER TABLE acc_trans ALTER cb_transaction SET NOT NULL;
+ALTER TABLE acc_trans ALTER fx_transaction SET NOT NULL;
index dbb8280..960ef5c 100644 (file)
@@ -8,3 +8,11 @@
   [% L.select_tag('settings.table', opts, default = SELF.profile.get('table'), style = 'width: 300px') %]
  </td>
 </tr>
+
+<tr>
+ <th align="right">[%- LxERP.t8('Existing customers/vendors with same customer/vendor number') %]:</th>
+ <td colspan="10">
+  [% opts = [ [ 'update_existing', LxERP.t8('Update properties of existing entries') ], [ 'insert_new', LxERP.t8('Insert with new customer/vendor number') ], [ 'skip', LxERP.t8('Skip entry') ] ] %]
+  [% L.select_tag('settings.update_policy', opts, default = SELF.profile.get('update_policy'), style = 'width: 300px') %]
+ </td>
+</tr>
index e6e9324..675790d 100644 (file)
@@ -81,7 +81,7 @@
   [% FOREACH row = Q %]
   <tr>
     <td></td>
-    <td>[% row.description %]</td>
+    <td>[% row.accno _ ' - ' IF l_accno and row.accno %][% row.description %]</td>
     <td align="right">[% LxERP.format_amount(row.this, decimalplaces) %]</td>
     [%- IF last_period %]
     <td align="right">[% LxERP.format_amount(row.last, decimalplaces) %]</td>