Revision 22150c52
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/DB/Invoice.pm | ||
---|---|---|
91 | 91 |
invoice => 1, |
92 | 92 |
type => 'invoice', |
93 | 93 |
storno => 0, |
94 |
paid => 0, |
|
94 | 95 |
employee_id => (SL::DB::Manager::Employee->current || SL::DB::Employee->new(id => $source->employee_id))->id, |
95 | 96 |
); |
96 | 97 |
|
... | ... | |
109 | 110 |
qw(parts_id description qty sellprice discount project_id |
110 | 111 |
serialnumber pricegroup_id ordnumber transdate cusordnumber unit |
111 | 112 |
base_qty subtotal longdescription lastcost price_factor_id)), |
112 |
deliverydate => $source_item->reqdate); |
|
113 |
deliverydate => $source_item->reqdate, |
|
114 |
fxsellprice => $source_item->sellprice,); |
|
113 | 115 |
} @{ $source->items }; |
114 | 116 |
|
115 | 117 |
$invoice->invoiceitems(\@items); |
... | ... | |
122 | 124 |
|
123 | 125 |
croak("Missing parameter 'ar_id'") unless $params{ar_id}; |
124 | 126 |
|
125 |
$self->db->do_transaction(sub { |
|
126 |
1; # dummy instruction for Emacs ;) |
|
127 |
|
|
127 |
my $worker = sub { |
|
128 | 128 |
my %data = $self->calculate_prices_and_taxes; |
129 | 129 |
|
130 | 130 |
$self->_post_create_assemblyitem_entries($data{assembly_items}); |
131 |
|
|
131 |
$self->create_trans_number; |
|
132 | 132 |
$self->save; |
133 | 133 |
|
134 | 134 |
$self->_post_add_acctrans($data{amounts_cogs}); |
... | ... | |
138 | 138 |
$self->_post_add_acctrans({ $params{ar_id} => $self->amount * -1 }); |
139 | 139 |
|
140 | 140 |
$self->_post_update_allocated($data{allocated}); |
141 |
}; |
|
142 |
|
|
143 |
if ($self->db->in_transaction) { |
|
144 |
$worker->(); |
|
145 |
} elsif (!$self->db->do_transaction($worker)) { |
|
146 |
$::lxdebug->message(0, "convert_to_invoice failed: " . join("\n", (split(/\n/, $self->db->error))[0..2])); |
|
147 |
return undef; |
|
148 |
} |
|
141 | 149 |
|
142 |
die; |
|
143 |
}); |
|
150 |
return $self; |
|
144 | 151 |
} |
145 | 152 |
|
146 | 153 |
sub _post_add_acctrans { |
... | ... | |
152 | 159 |
chart_id => $chart_id, |
153 | 160 |
amount => $spec->{amount}, |
154 | 161 |
taxkey => $spec->{taxkey}, |
155 |
project_id => $self->project_id, |
|
162 |
project_id => $self->globalproject_id,
|
|
156 | 163 |
transdate => $self->transdate)->save; |
157 | 164 |
} |
158 | 165 |
} |
... | ... | |
189 | 196 |
my ($self, $allocated) = @_; |
190 | 197 |
|
191 | 198 |
while (my ($invoice_id, $diff) = each %{ $allocated }) { |
192 |
SL::DB::Manager::InvoiceItem->update_all(set => { allocated => { sql => [ 'allocated + ?', $diff ] } },
|
|
199 |
SL::DB::Manager::InvoiceItem->update_all(set => { allocated => { sql => "allocated + $diff" } },
|
|
193 | 200 |
where => [ id => $invoice_id ]); |
194 | 201 |
} |
195 | 202 |
} |
Auch abrufbar als: Unified diff
Rechnung posten gefixt