Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 03ff37cb

Von Niclas Zimmermann vor fast 12 Jahren hinzugefügt

  • ID 03ff37cb621e68f7d224d2520099ee86f612f833
  • Vorgänger 2c86cb0a
  • Nachfolger 0f0f4263

tax_id in acc_trans

Dieser Commit enthält das Update-Script um eine neue Spalte Namens
'tax_id' in die Tabelle 'acc_trans' einzufügen. Diese Spalte hat
Constrait NOT NULL und einen Fremdschlüssel auf die id von tax.

Das Pflichtfeld wird jetzt immer geschrieben bei:

-VK-Rechnungen (auch automatisch erzeugten)
-EK-Rechnungen
-Kreditorenbuchungen
-Debitorenbuchungen
-Dialogbuchungen

Durch das Feld 'tax_id' können in der Tabelle tax der
Steuerschlüssel und der Steuersatz ausgelesen werden.

In diesem Commit wird allerdings der Wert in tax_id nur geschrieben,
im Moment wird er noch nirgendwo ausgelesen.

Unterschiede anzeigen:

SL/AP.pm
208 208
        # insert detail records in acc_trans
209 209
        $query =
210 210
          qq|INSERT INTO acc_trans | .
211
          qq|  (trans_id, chart_id, amount, transdate, project_id, taxkey)| .
211
          qq|  (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)| .
212 212
          qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | .
213
          qq|  ?, ?, ?, ?)|;
213
          qq|  ?, ?, ?, ?, ?)|;
214 214
        @values = ($form->{id}, $form->{AP_amounts}{"amount_$i"},
215 215
                   $form->{"amount_$i"}, conv_date($form->{transdate}),
216
                   $project_id, $form->{"taxkey_$i"});
216
                   $project_id, $form->{"taxkey_$i"}, conv_i($form->{"tax_id_$i"}));
217 217
        do_query($form, $dbh, $query, @values);
218 218

  
219 219
        if ($form->{"tax_$i"} != 0) {
220 220
          # insert detail records in acc_trans
221 221
          $query =
222 222
            qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | .
223
            qq|  project_id, taxkey) | .
223
            qq|  project_id, taxkey, tax_id) | .
224 224
            qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | .
225
            qq|  ?, ?, ?, ?)|;
225
            qq|  ?, ?, ?, ?, ?)|;
226 226
          @values = ($form->{id}, $form->{AP_amounts}{"tax_$i"},
227 227
                     $form->{"tax_$i"}, conv_date($form->{transdate}),
228
                     $project_id, $form->{"taxkey_$i"});
228
                     $project_id, $form->{"taxkey_$i"}, conv_i($form->{"tax_id_$i"}));
229 229
          do_query($form, $dbh, $query, @values);
230 230
        }
231 231

  
......
234 234

  
235 235
    # add payables
236 236
    $query =
237
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) | .
237
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) | .
238 238
      qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, | .
239
      qq|        (SELECT taxkey_id FROM chart WHERE accno = ?))|;
239
      qq|        (SELECT taxkey_id FROM chart WHERE accno = ?),| . 
240
      qq|        (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
240 241
    @values = ($form->{id}, $form->{AP_amounts}{payables}, $form->{payables},
241
               conv_date($form->{transdate}), $form->{AP_amounts}{payables});
242
               conv_date($form->{transdate}), $form->{AP_amounts}{payables}, $form->{AP_amounts}{payables}, conv_date($form->{transdate}));
242 243
    do_query($form, $dbh, $query, @values);
243 244
  }
244 245

  
......
282 283
                            2);
283 284
      if ($form->{payables}) {
284 285
        $query =
285
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey) | .
286
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id) | .
286 287
          qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, | .
287
          qq|        (SELECT taxkey_id FROM chart WHERE accno = ?))|;
288
          qq|        (SELECT taxkey_id FROM chart WHERE accno = ?),| .
289
          qq|        (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
288 290
        @values = ($form->{id}, $form->{AP_payables}, $amount,
289 291
                   conv_date($form->{"datepaid_$i"}), $project_id,
290
                   $form->{AP_payables});
292
                   $form->{AP_payables}, $form->{AP_payables}, conv_date($form->{"datepaid_$i"}));
291 293
        do_query($form, $dbh, $query, @values);
292 294
      }
293 295
      $form->{payables} = $amount;
......
295 297
      # add payment
296 298
      my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
297 299
      $query =
298
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey) | .
300
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id) | .
299 301
        qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, | .
300
        qq|        (SELECT taxkey_id FROM chart WHERE accno = ?))|;
302
        qq|        (SELECT taxkey_id FROM chart WHERE accno = ?), | . 
303
        qq|        (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
301 304
      @values = ($form->{id}, $form->{"AP_paid_account_$i"}, $form->{"paid_$i"},
302 305
                 conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"},
303
                 $form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"});
306
                 $form->{"memo_$i"}, $project_id, $form->{"AP_paid_account_$i"},
307
                 $form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"}));
304 308
      do_query($form, $dbh, $query, @values);
305 309

  
306 310
      # add exchange rate difference
......
309 313
                            ($form->{"exchangerate_$i"} - 1), 2);
310 314
      if ($amount != 0) {
311 315
        $query =
312
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) | .
316
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) | .
313 317
          qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | .
314
          qq|        (SELECT taxkey_id FROM chart WHERE accno = ?))|;
318
          qq|        (SELECT taxkey_id FROM chart WHERE accno = ?), | .
319
          qq|        (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
315 320
        @values = ($form->{id}, $form->{"AP_paid_account_$i"}, $amount,
316 321
                   conv_date($form->{"datepaid_$i"}), $project_id,
317
                   $form->{"AP_paid_account_$i"});
322
                   $form->{"AP_paid_account_$i"},
323
                   $form->{"AP_paid_account_$i"}, conv_date($form->{"datepaid_$i"}));
318 324
        do_query($form, $dbh, $query, @values);
319 325
      }
320 326

  
......
326 332

  
327 333
      if ($amount != 0) {
328 334
        $query =
329
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey) | .
335
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id) | .
330 336
          qq|VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, | .
331
          qq|        (SELECT taxkey_id FROM chart WHERE accno = ?))|;
337
          qq|        (SELECT taxkey_id FROM chart WHERE accno = ?)| .
338
          qq|        (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
332 339
        @values = ($form->{id}, ($amount > 0) ?
333 340
                   $form->{fxgain_accno} : $form->{fxloss_accno},
334 341
                   $amount, conv_date($form->{"datepaid_$i"}), $project_id,
335 342
                   ($amount > 0) ?
336
                   $form->{fxgain_accno} : $form->{fxloss_accno});
343
                   $form->{fxgain_accno} : $form->{fxloss_accno},
344
                   ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}, conv_date($form->{"datepaid_$i"}));
337 345
        do_query($form, $dbh, $query, @values);
338 346
      }
339 347

  
SL/AR.pm
172 172
        my $project_id = conv_i($form->{"project_id_$i"});
173 173

  
174 174
        # insert detail records in acc_trans
175
        $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey)
176
                     VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|;
175
        $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)
176
                     VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|;
177 177
        @values = (conv_i($form->{id}), $form->{AR_amounts}{"amount_$i"}, conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), $project_id,
178
                   conv_i($form->{"taxkey_$i"}));
178
                   conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"}));
179 179
        do_query($form, $dbh, $query, @values);
180 180

  
181 181
        if ($form->{"tax_$i"} != 0) {
182 182
          # insert detail records in acc_trans
183
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey)
184
                       VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|;
183
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)
184
                       VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|;
185 185
          @values = (conv_i($form->{id}), $form->{AR_amounts}{"tax_$i"}, conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), $project_id,
186
                     conv_i($form->{"taxkey_$i"}));
186
                     conv_i($form->{"taxkey_$i"}), conv_i($form->{"tax_id_$i"}));
187 187
          do_query($form, $dbh, $query, @values);
188 188
        }
189 189
      }
190 190
    }
191 191

  
192 192
    # add recievables
193
    $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey)
194
                 VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|;
195
    @values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}), $form->{AR_amounts}{receivables});
193
    $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id)
194
                 VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?),
195
                 (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
196
    @values = (conv_i($form->{id}), $form->{AR_amounts}{receivables}, conv_i($form->{receivables}), conv_date($form->{transdate}),
197
                $form->{AR_amounts}{receivables}, $form->{AR_amounts}{receivables}, conv_date($form->{transdate}));
196 198
    do_query($form, $dbh, $query, @values);
197 199

  
198 200
  } else {
......
229 231

  
230 232
      if ($amount != 0) {
231 233
        # add receivable
232
        $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey)
233
                     VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|;
234
        @values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables});
234
        $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id, taxkey, tax_id)
235
                     VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?),
236
                     (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
237
        @values = (conv_i($form->{id}), $form->{AR}{receivables}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{receivables}, $form->{AR}{receivables}, conv_date($form->{"datepaid_$i"}));
235 238
        do_query($form, $dbh, $query, @values);
236 239
      }
237 240

  
......
240 243
        my $project_id = conv_i($form->{"paid_project_id_$i"});
241 244
        my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
242 245
        $amount = $form->{"paid_$i"} * -1;
243
        $query  = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey)
244
                     VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|;
245
        @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"});
246
        $query  = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, project_id, taxkey, tax_id)
247
                     VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE accno = ?),
248
                     (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
249
        @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $form->{AR}{"paid_$i"},
250
                    $form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"}));
246 251
        do_query($form, $dbh, $query, @values);
247 252

  
248 253
        # exchangerate difference for payment
249 254
        $amount = $form->round_amount( $form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) * -1, 2);
250 255

  
251 256
        if ($amount != 0) {
252
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey)
253
                       VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|;
254
          @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"});
257
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id)
258
                       VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?),
259
                       (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
260
          @values = (conv_i($form->{id}), $form->{AR}{"paid_$i"}, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $form->{AR}{"paid_$i"},
261
                    $form->{AR}{"paid_$i"}, conv_date($form->{"datepaid_$i"}));
255 262
          do_query($form, $dbh, $query, @values);
256 263
        }
257 264

  
......
260 267

  
261 268
        if ($amount != 0) {
262 269
          my $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno};
263
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey)
264
                       VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?))|;
265
          @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno);
270
          $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id, taxkey, tax_id)
271
                       VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 't', 'f', ?, (SELECT taxkey_id FROM chart WHERE accno = ?),
272
                       (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
273
          @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{"datepaid_$i"}), $project_id, $accno, $accno, conv_date($form->{"datepaid_$i"}));
266 274
          do_query($form, $dbh, $query, @values);
267 275
        }
268 276
      }
SL/DB/Helper/PriceTaxCalculator.pm
119 119
  $self->netamount($self->netamount + $sellprice * $item->qty / $item->price_factor);
120 120

  
121 121
  my $chart = $item->part->get_chart(type => $data->{is_sales} ? 'income' : 'expense', taxzone => $self->taxzone_id);
122
  $data->{amounts}->{ $chart->id }           ||= { taxkey => $taxkey->taxkey_id, amount => 0 };
122
  $data->{amounts}->{ $chart->id }           ||= { taxkey => $taxkey->taxkey_id, tax_id => $taxkey->tax_id, amount => 0 };
123 123
  $data->{amounts}->{ $chart->id }->{amount}  += $linetotal;
124 124

  
125 125
  push @{ $data->{assembly_items} }, [];
SL/DB/Invoice.pm
169 169
sub _post_add_acctrans {
170 170
  my ($self, $entries) = @_;
171 171

  
172
  my $default_tax_id = SL::DB::Manager::Tax->find_by(taxkey => 0)->id;
173

  
172 174
  while (my ($chart_id, $spec) = each %{ $entries }) {
173
    $spec = { taxkey => 0, amount => $spec } unless ref $spec;
175
    $spec = { taxkey => 0, tax_id => $default_tax_id, amount => $spec } unless ref $spec;
174 176
    SL::DB::AccTransaction->new(trans_id   => $self->id,
175 177
                                chart_id   => $chart_id,
176 178
                                amount     => $spec->{amount},
179
                                tax_id     => $spec->{tax_id},
177 180
                                taxkey     => $spec->{taxkey},
178 181
                                project_id => $self->globalproject_id,
179 182
                                transdate  => $self->transdate)->save;
SL/DB/MetaSetup/AccTransaction.pm
26 26
    taxkey         => { type => 'integer' },
27 27
    itime          => { type => 'timestamp', default => 'now()' },
28 28
    mtime          => { type => 'timestamp' },
29
    tax_id         => { type => 'integer', not_null => 1 },
29 30
  ],
30 31

  
31 32
  primary_key_columns => [ 'acc_trans_id' ],
32 33

  
33
  allow_inline_column_values => 1,
34

  
35 34
  foreign_keys => [
36 35
    chart => {
37 36
      class       => 'SL::DB::Chart',
SL/GL.pm
157 157
    if ($amount != 0) {
158 158
      $query =
159 159
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
160
                                  source, memo, project_id, taxkey, ob_transaction, cb_transaction)
160
                                  source, memo, project_id, taxkey, ob_transaction, cb_transaction, tax_id)
161 161
           VALUES (?, (SELECT id FROM chart WHERE accno = ?),
162
                   ?, ?, ?, ?, ?, ?, ?, ?)|;
162
                   ?, ?, ?, ?, ?, ?, ?, ?, ?)|;
163 163
      @values = (conv_i($form->{id}), $accno, $amount, conv_date($form->{transdate}),
164
                 $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f');
164
                 $form->{"source_$i"}, $form->{"memo_$i"}, $project_id, $taxkey, $form->{ob_transaction} ? 't' : 'f', $form->{cb_transaction} ? 't' : 'f', conv_i($form->{"tax_id_$i"}));
165 165
      do_query($form, $dbh, $query, @values);
166 166
    }
167 167

  
......
169 169
      # add taxentry
170 170
      $query =
171 171
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate,
172
                                  source, memo, project_id, taxkey)
172
                                  source, memo, project_id, taxkey, tax_id)
173 173
           VALUES (?, (SELECT chart_id FROM tax WHERE id = ?),
174
                   ?, ?, ?, ?, ?, ?)|;
174
                   ?, ?, ?, ?, ?, ?, ?)|;
175 175
      @values = (conv_i($form->{id}), conv_i($form->{"tax_id_$i"}),
176 176
                 $tax, conv_date($form->{transdate}), $form->{"source_$i"},
177
                 $form->{"memo_$i"}, $project_id, $taxkey);
177
                 $form->{"memo_$i"}, $project_id, $taxkey, conv_i($form->{"tax_id_$i"}));
178 178
      do_query($form, $dbh, $query, @values);
179 179
    }
180 180
  }
SL/IR.pm
269 269

  
270 270
            # allocated >= 0
271 271
            # add entry for inventory, this one is for the sold item
272
            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?))|;
273
            @values = ($ref->{trans_id},  $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id});
272
            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey_id FROM chart WHERE id = ?),
273
                                (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
274
            @values = ($ref->{trans_id},  $ref->{inventory_accno_id}, $linetotal, $ref->{transdate}, $ref->{inventory_accno_id}, $ref->{inventory_accno_id}, $ref->{transdate});
274 275
            do_query($form, $dbh, $query, @values);
275 276

  
276 277
# add expense
277
            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?))|;
278
            @values = ($ref->{trans_id},  $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id});
278
            $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, tax_id) VALUES (?, ?, ?, ?, (SELECT taxkey from tax WHERE chart_id = ?),
279
                                (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
280
            @values = ($ref->{trans_id},  $ref->{expense_accno_id}, ($linetotal * -1), $ref->{transdate}, $ref->{expense_accno_id}, $ref->{expense_accno_id}, $ref->{transdate});
279 281
            do_query($form, $dbh, $query, @values);
280 282
          }
281 283
        };
......
478 480

  
479 481
      next if $payments_only || !$form->{amount}{$trans_id}{$accno};
480 482

  
481
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
483
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id)
482 484
                  VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
483
                  (SELECT taxkey_id  FROM chart WHERE accno = ?), ?)|;
485
                  (SELECT taxkey_id  FROM chart WHERE accno = ?), ?,
486
                  (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
484 487
      @values = ($trans_id, $accno, $form->{amount}{$trans_id}{$accno},
485
                 conv_date($form->{invdate}), $accno, $project_id);
488
                 conv_date($form->{invdate}), $accno, $project_id, $accno, conv_date($form->{invdate}));
486 489
      do_query($form, $dbh, $query, @values);
487 490
    }
488 491
  }
......
517 520

  
518 521
    # record AP
519 522
    if ($form->{amount}{ $form->{id} }{ $form->{AP} } != 0) {
520
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
523
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id, tax_id)
521 524
                  VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
522
                          (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
525
                          (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
526
                          (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
523 527
      @values = (conv_i($form->{id}), $form->{AP}, $amount,
524
                 $form->{"datepaid_$i"}, $form->{AP}, $project_id);
528
                 $form->{"datepaid_$i"}, $form->{AP}, $project_id, $form->{AP}, conv_date($form->{"datepaid_$i"}));
525 529
      do_query($form, $dbh, $query, @values);
526 530
    }
527 531

  
......
529 533
    my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
530 534

  
531 535
    $query =
532
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id)
536
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id, tax_id)
533 537
                VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?,
534
                (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
538
                (SELECT taxkey_id FROM chart WHERE accno = ?), ?,
539
                (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
535 540
    @values = (conv_i($form->{id}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"},
536
               $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id);
541
               $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id, $accno, conv_date($form->{"datepaid_$i"}));
537 542
    do_query($form, $dbh, $query, @values);
538 543

  
539 544
    $exchangerate = 0;
......
571 576
      $form->{fx}{$accno}{$transdate} = $form->round_amount($form->{fx}{$accno}{$transdate}, 2);
572 577
      next if ($form->{fx}{$accno}{$transdate} == 0);
573 578

  
574
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id)
575
                  VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?)|;
576
      @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id);
579
      $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id, tax_id)
580
                  VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1', 0, ?,
581
                  (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1))|;
582
      @values = (conv_i($form->{id}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $project_id, $accno, $form->{fx}{$accno}{$transdate});
577 583
      do_query($form, $dbh, $query, @values);
578 584
    }
579 585
  }
SL/IS.pm
822 822

  
823 823
  $project_id = conv_i($form->{"globalproject_id"});
824 824

  
825
  my $taxdate = $form->{deliverydate} ? $form->{deliverydate} : $form->{invdate};
826

  
825 827
  foreach my $trans_id (keys %{ $form->{amount_cogs} }) {
826 828
    foreach my $accno (keys %{ $form->{amount_cogs}{$trans_id} }) {
827 829
      next unless ($form->{expense_inventory} =~ /\Q$accno\E/);
......
830 832

  
831 833
      if (!$payments_only && ($form->{amount_cogs}{$trans_id}{$accno} != 0)) {
832 834
        $query =
833
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
834
               VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 0, ?)|;
835
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
836
               VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?)|;
835 837
        @values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id));
836 838
        do_query($form, $dbh, $query, @values);
837 839
        $form->{amount_cogs}{$trans_id}{$accno} = 0;
......
843 845

  
844 846
      if (!$payments_only && ($form->{amount_cogs}{$trans_id}{$accno} != 0)) {
845 847
        $query =
846
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
847
               VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, 0, ?)|;
848
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
849
               VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?)|;
848 850
        @values = (conv_i($trans_id), $accno, $form->{amount_cogs}{$trans_id}{$accno}, conv_date($form->{invdate}), conv_i($project_id));
849 851
        do_query($form, $dbh, $query, @values);
850 852
      }
......
859 861

  
860 862
      if (!$payments_only && ($form->{amount}{$trans_id}{$accno} != 0)) {
861 863
        $query =
862
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
864
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
863 865
             VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
866
                     (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1),
864 867
                     (SELECT taxkey_id  FROM chart WHERE accno = ?), ?)|;
865
        @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_i($project_id));
868
        @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id));
866 869
        do_query($form, $dbh, $query, @values);
867 870
        $form->{amount}{$trans_id}{$accno} = 0;
868 871
      }
......
873 876

  
874 877
      if (!$payments_only && ($form->{amount}{$trans_id}{$accno} != 0)) {
875 878
        $query =
876
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
879
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
877 880
             VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
881
                     (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1),
878 882
                     (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
879
        @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_i($project_id));
883
        @values = (conv_i($trans_id), $accno, $form->{amount}{$trans_id}{$accno}, conv_date($form->{invdate}), $accno, conv_date($taxdate), $accno, conv_i($project_id));
880 884
        do_query($form, $dbh, $query, @values);
881 885
      }
882 886
    }
......
922 926

  
923 927
      if ($form->{amount}{ $form->{id} }{ $form->{AR} } != 0) {
924 928
        $query =
925
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, taxkey, project_id)
929
        qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id)
926 930
           VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?,
931
                   (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1),
927 932
                   (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
928
        @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, $project_id);
933
        @values = (conv_i($form->{"id"}), $form->{AR}, $amount, $form->{"datepaid_$i"}, $form->{AR}, conv_date($taxdate), $form->{AR}, $project_id);
929 934
        do_query($form, $dbh, $query, @values);
930 935
      }
931 936

  
......
934 939
      my $gldate = (conv_date($form->{"gldate_$i"}))? conv_date($form->{"gldate_$i"}) : conv_date($form->current_date($myconfig));
935 940

  
936 941
      $query =
937
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, taxkey, project_id)
942
      qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, gldate, source, memo, tax_id, taxkey, project_id)
938 943
         VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, ?, ?, ?,
944
                 (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1),
939 945
                 (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
940 946
      @values = (conv_i($form->{"id"}), $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"},
941
                 $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, $project_id);
947
                 $gldate, $form->{"source_$i"}, $form->{"memo_$i"}, $accno, conv_date($taxdate), $accno, $project_id);
942 948
      do_query($form, $dbh, $query, @values);
943 949

  
944 950
      # exchangerate difference
......
978 984
      if ( $form->{fx}{$accno}{$transdate} != 0 ) {
979 985

  
980 986
        $query =
981
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, taxkey, project_id)
987
          qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, tax_id, taxkey, project_id)
982 988
             VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, '0', '1',
983
             (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
984
        @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_i($project_id));
989
                 (SELECT tax_id FROM taxkeys WHERE chart_id= (SELECT id  FROM chart WHERE accno = ?) AND startdate <= ? ORDER BY startdate DESC LIMIT 1),
990
                 (SELECT taxkey_id FROM chart WHERE accno = ?), ?)|;
991
        @values = (conv_i($form->{"id"}), $accno, $form->{fx}{$accno}{$transdate}, conv_date($transdate), $accno, conv_date($taxdate), $accno, conv_i($project_id));
985 992
        do_query($form, $dbh, $query, @values);
986 993
      }
987 994
    }
sql/Pg-upgrade2/add_fkey_tax_id_to_acc_trans.sql
1
-- @tag: add_fkey_tax_id_to_acc_trans
2
-- @description: Setzt einen Fremdschlüssel zu der Tabellenspalte tax_id in der acc_trans
3
-- @depends: release_3_0_0
4

  
5
ALTER TABLE acc_trans ADD FOREIGN KEY (tax_id) REFERENCES tax(id);
sql/Pg-upgrade2/add_tax_id_to_acc_trans.sql
1
-- @tag: add_tax_id_to_acc_trans
2
-- @description: Neue Spalte tax_id in der acc_trans
3
-- @depends: release_2_7_0 
4

  
5
  --Neue Spalte tax_id in acc_trans:
6
  ALTER TABLE acc_trans ADD tax_id integer;
7

  
8
  --Spalte mit Werten füllen:
9
  UPDATE acc_trans ac SET tax_id=
10
                (select tk.tax_id from taxkeys tk 
11
                      where tk.taxkey_id=ac.taxkey 
12
                      AND tk.startdate <= COALESCE(
13
                            (select ar.deliverydate from ar where ar.id=ac.trans_id), 
14
                            (select ar.transdate from ar where ar.id=ac.trans_id), 
15
                            (select ap.transdate from ap where ap.id=ac.trans_id), 
16
                            (select gl.transdate from gl where gl.id=ac.trans_id), 
17
                            ac.transdate )
18
                      order by startdate desc limit 1);
19

  
20
  --Spalten, die noch null sind (nur bei Einträgen möglich, wo auch taxkey null ist)
21
  UPDATE acc_trans SET tax_id= (SELECT id FROM tax WHERE taxkey=0 LIMIT 1) where tax_id is null;
22
 
23
  --tax_id als Pflichtfeld definieren:
24
  ALTER TABLE acc_trans ALTER tax_id SET NOT NULL;
25

  

Auch abrufbar als: Unified diff