Revision 6e083cb8
Von Bernd Bleßmann vor mehr als 5 Jahren hinzugefügt
bin/mozilla/ap.pl | ||
---|---|---|
47 | 47 |
use SL::DB::Chart; |
48 | 48 |
use SL::DB::Currency; |
49 | 49 |
use SL::DB::Default; |
50 |
use SL::DB::Order; |
|
50 | 51 |
use SL::DB::PurchaseInvoice; |
51 | 52 |
use SL::DB::RecordTemplate; |
52 | 53 |
use SL::DB::Tax; |
... | ... | |
649 | 650 |
# calculate tax exactly the same way as AP in post_transaction via form->calculate_tax |
650 | 651 |
my $tmpnetamount; |
651 | 652 |
($tmpnetamount,$form->{"tax_$i"}) = $form->calculate_tax($form->{"amount_$i"},$rate,$form->{taxincluded},2); |
652 |
|
|
653 | 653 |
$totaltax += $form->{"tax_$i"}; |
654 | 654 |
map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; |
655 | 655 |
$count++; |
... | ... | |
899 | 899 |
|
900 | 900 |
$main::auth->assert('ap_transactions'); |
901 | 901 |
|
902 |
map { delete $form->{$_} } qw(printed emailed queued invnumber deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno); |
|
902 |
map { delete $form->{$_} } qw(printed emailed queued invnumber deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno convert_from_oe_id);
|
|
903 | 903 |
$form->{paidaccounts} = 1; |
904 | 904 |
$form->{rowcount}--; |
905 | 905 |
|
... | ... | |
1183 | 1183 |
$main::lxdebug->leave_sub(); |
1184 | 1184 |
} |
1185 | 1185 |
|
1186 |
sub add_from_purchase_order { |
|
1187 |
$main::auth->assert('ap_transactions'); |
|
1188 |
|
|
1189 |
return if !$::form->{id}; |
|
1190 |
|
|
1191 |
my $order_id = delete $::form->{id}; |
|
1192 |
my $order = SL::DB::Order->new(id => $order_id)->load; |
|
1193 |
|
|
1194 |
return if $order->type ne 'purchase_order'; |
|
1195 |
|
|
1196 |
my $today = DateTime->today_local; |
|
1197 |
$::form->{title} = "Add"; |
|
1198 |
$::form->{vc} = 'vendor'; |
|
1199 |
$::form->{vendor_id} = $order->customervendor->id; |
|
1200 |
$::form->{vendor} = $order->vendor->name; |
|
1201 |
$::form->{convert_from_oe_id} = $order->id; |
|
1202 |
$::form->{globalproject_id} = $order->globalproject_id; |
|
1203 |
$::form->{ordnumber} = $order->number; |
|
1204 |
$::form->{department_id} = $order->department_id; |
|
1205 |
$::form->{currency} = $order->currency->name; |
|
1206 |
$::form->{taxincluded} = 1; # we use amount below, so tax is included |
|
1207 |
$::form->{transdate} = $today->to_kivitendo; |
|
1208 |
$::form->{duedate} = $today->to_kivitendo; |
|
1209 |
$::form->{duedate} = $order->vendor->payment->calc_date(reference_date => $today)->to_kivitendo if $order->vendor->payment; |
|
1210 |
|
|
1211 |
create_links(); |
|
1212 |
|
|
1213 |
my $config_po_ap_workflow_chart_id = $::instance_conf->get_workflow_po_ap_chart_id; |
|
1214 |
|
|
1215 |
my ($first_taxchart, $default_taxchart, $taxchart_to_use); |
|
1216 |
my @taxcharts = (); |
|
1217 |
@taxcharts = GL->get_active_taxes_for_chart($config_po_ap_workflow_chart_id, $::form->{transdate}) if (defined $config_po_ap_workflow_chart_id); |
|
1218 |
foreach my $item (@taxcharts) { |
|
1219 |
$first_taxchart //= $item; |
|
1220 |
$default_taxchart = $item if $item->{is_default}; |
|
1221 |
} |
|
1222 |
$taxchart_to_use = $default_taxchart // $first_taxchart; |
|
1223 |
|
|
1224 |
my %pat = $order->calculate_prices_and_taxes; |
|
1225 |
my $row = 1; |
|
1226 |
foreach my $amount_chart (keys %{$pat{amounts}}) { |
|
1227 |
my $tax = SL::DB::Manager::Tax->find_by(id => $pat{amounts}->{$amount_chart}->{tax_id}); |
|
1228 |
# If tax chart from order for this amount is active, use it. Use default or first tax chart for selected chart else. |
|
1229 |
if (defined $config_po_ap_workflow_chart_id) { |
|
1230 |
$taxchart_to_use = (first {$_->{id} == $tax->id} @taxcharts) // $taxchart_to_use; |
|
1231 |
} else { |
|
1232 |
$taxchart_to_use = $tax; |
|
1233 |
} |
|
1234 |
|
|
1235 |
$::form->{"AP_amount_chart_id_$row"} = $config_po_ap_workflow_chart_id // $amount_chart; |
|
1236 |
$::form->{"previous_AP_amount_chart_id_$row"} = $::form->{"AP_amount_chart_id_$row"}; |
|
1237 |
$::form->{"amount_$row"} = $::form->format_amount(\%::myconfig, $pat{amounts}->{$amount_chart}->{amount} * (1 + $tax->rate), 2); |
|
1238 |
$::form->{"taxchart_$row"} = $taxchart_to_use->id . '--' . $taxchart_to_use->rate; |
|
1239 |
$::form->{"project_id_$row"} = $order->globalproject_id; |
|
1240 |
|
|
1241 |
$row++; |
|
1242 |
} |
|
1243 |
|
|
1244 |
my $last_used_ap_chart = SL::DB::Vendor->load_cached($::form->{vendor_id})->last_used_ap_chart; |
|
1245 |
$::form->{"AP_amount_chart_id_$row"} = $last_used_ap_chart->id if $last_used_ap_chart; |
|
1246 |
$::form->{rowcount} = $row; |
|
1247 |
|
|
1248 |
update( |
|
1249 |
keep_rows_without_amount => 1, |
|
1250 |
dont_add_new_row => 1, |
|
1251 |
); |
|
1252 |
} |
|
1253 |
|
|
1186 | 1254 |
sub setup_ap_search_action_bar { |
1187 | 1255 |
my %params = @_; |
1188 | 1256 |
|
Auch abrufbar als: Unified diff
Neuer Workflow Lieferantenauftrag->Kreditorenbuchung
Für jedes Aufwandskonto der Positionen im Lieferantenauftrag wird eine
Zeile in der Kreditorenbuchung erstellt. Gebucht wird standardmäßig
auf des entsprechende Aufwandskonto. In der Mandantenkonfiguration
kann unter Standardkonten ein Konto ausgewählt werden, auf das dann
alle Zeilen gebucht werden.
Die Steuern werden übernommen, sofern diese für das ausgewählte
Aufwandskonto gültig sind. Ansonsten wird die Default-Steuer für das
Aufwandskonto gesetzt.
Der Quellauftrag wird geschlossen, wenn der Betrag aller
Kreditorenbuchungen, die aus Workflows aus dem Quellauftrag entstanden
sind, gleich dem Betrag des Quellauftrags ist.