⚲
Projekt
Allgemein
Profil
Anmelden
Hauptseite
Projekte
Hilfe
Suche
:
projekt kivitendo
Alle Projekte
projekt kivitendo
Übersicht
Aktivität
Roadmap
Tickets
Aufgewendete Zeit
News
Dokumente
Wiki
Foren
Repository
Herunterladen (17,9 KB)
Statistiken
| Zweig:
2017-validator-args
2018-cvar-presenter
2020-cgi-removal
2020-helper-number
2020-inventory-helper
2020-inventory-helper2
2020-leistungsdatum
2021-delivery-order-controller-3
2021-delivery-order-controller-5
2021-delivery-order-controller-7
2021-delivery-order-controller-8
2021-deliver"DeliveryOrder.pm.html#L314" data-txt="314">
$longdescription
.=
'
<ul>
';
$longdescription
.=
$entry
->
{
content
};
$longdescription
.=
'
</ul>
';
}
my
$item
=
SL::DB::
DeliveryOrderItem
->
new
(
parts_id
=>
$part_by_part_id
{
$key
}
->
id
,
description
=>
$part_by_part_id
{
$key
}
->
description
,
qty
=>
$qty
,
base_qty
=>
$h_unit
->
convert_to
(
$qty
,
$part_by_part_id
{
$key
}
->
unit_obj
),
unit_obj
=>
$h_unit
,
sellprice
=>
$part_by_part_id
{
$key
}
->
sellprice
,
# Todo: use price rules to get sellprice
longdescription
=>
$longdescription
,
);
push
@items
,
$item
;
}
my
$delivery_order
;
if
(
$params
{
related_order
})
{
# collect suitable items in related order
my
@items_to_use
;
my
@new_attributes
;
foreach
my
$item
(
@items
)
{
my
$item_to_use
=
first
{
$item
->
parts_id
==
$_
->
parts_id
}
@
{
$params
{
related_order
}
->
items_sorted
};
die
"
no suitable item found in related order
"
if
!
$item_to_use
;
my
%new_attributes
;
$new_attributes
{
$_
}
=
$item
->
$_
for
qw(qty base_qty unit_obj longdescription)
;
push
@items_to_use
,
$item_to_use
;
push
@new_attributes
,
\
%new_attributes
;
}
$delivery_order
=
$class
->
new_from
(
$params
{
related_order
},
items
=>
\
@items_to_use
,
%params
);
pairwise
{
$a
->
assign_attributes
(
%$b
)
}
@
{
$delivery_order
->
items
},
@new_attributes
;
}
else
{
my
%args
=
(
is_sales
=>
1
,
order_type
=>
'
sales_delivery_order
',
delivered
=>
0
,
customer_id
=>
$sources
->
[
0
]
->
customer_id
,
taxzone_id
=>
$sources
->
[
0
]
->
customer
->
taxzone_id
,
currency_id
=>
$sources
->
[
0
]
->
customer
->
currency_id
,
employee_id
=>
SL::DB::Manager::
Employee
->
current
->
id
,
salesman_id
=>
SL::DB::Manager::
Employee
->
current
->
id
,
items
=>
\
@items
,
);
$delivery_order
=
$class
->
new
(
%args
);
$delivery_order
->
assign_attributes
(
%
{
$params
{
attributes
}
})
if
$params
{
attributes
};
}
return
$delivery_order
;
}
# legacy for compatibility
# use type_data cusomtervendor and transfer direction instead
sub
is_sales
{
if
(
$_
[
0
]
->
order_type
)
{
return
SL::DB::DeliveryOrder::TypeData::
get3
(
$_
[
0
]
->
order_type
,
"
properties
",
"
is_customer
");
}
return
$_
[
0
]{
is_sales
};
}
sub
customervendor
{
SL::DB::DeliveryOrder::TypeData::
get3
(
$_
[
0
]
->
order_type
,
"
properties
",
"
is_customer
")
?
$_
[
0
]
->
customer
:
$_
[
0
]
->
vendor
;
}
sub
convert_to_invoice
{
my
(
$self
,
%params
)
=
@_
;
croak
("
Conversion to invoices is only supported for sales records
")
unless
$self
->
customer_id
;
my
$invoice
;
if
(
!
$self
->
db
->
with_transaction
(
sub
{
require
SL::DB::
Invoice
;
$invoice
=
SL::DB::
Invoice
->
new_from
(
$self
,
%params
)
->
post
||
die
;
$self
->
link_to_record
(
$invoice
);
# TODO extend link_to_record for items, otherwise long-term no d.r.y.
foreach
my
$item
(
@
{
$invoice
->
items
})
{
foreach
(
qw(delivery_order_items)
)
{
# expand if needed (orderitems)
if
(
$item
->
{"
converted_from_
${_}
_id
"})
{
die
unless
$item
->
{
id
};
RecordLinks
->
create_links
('
mode
'
=>
'
ids
',
'
from_table
'
=>
$_
,
'
from_ids
'
=>
$item
->
{"
converted_from_
${_}
_id
"},
'
to_table
'
=>
'
invoice
',
'
to_id
'
=>
$item
->
{
id
},
)
||
die
;
delete
$item
->
{"
converted_from_
${_}
_id
"};
}
}
}
$self
->
update_attributes
(
closed
=>
1
);
1
;
}))
{
return
undef
;
}
return
$invoice
;
}
sub
digest
{
my
(
$self
)
=
@_
;
sprintf
"
%s %s (%s)
",
$self
->
donumber
,
$self
->
customervendor
->
name
,
$self
->
date
->
to_kivitendo
;
}
1
;
__END__
=pod
=encoding utf8
=head1 NAME
SL::DB::DeliveryOrder - Rose model for delivery orders (table
"delivery_orders")
=head1 FUNCTIONS
=over 4
=item C<date>
An alias for C<transdate> for compatibility with other sales/purchase models.
=item C<displayable_name>
Returns a human-readable and translated description of the delivery order, consisting of
record type and number, e.g. "Verkaufslieferschein 123".
=item C<displayable_state>
Returns a human-readable description of the state regarding being
closed and delivered.
=item C<items>
An alias for C<delivery_order_items> for compatibility with other
sales/purchase models.
=item C<new_from $source, %params>
Creates a new C<SL::DB::DeliveryOrder> instance and copies as much
information from C<$source> as possible. At the moment only instances
of C<SL::DB::Order> (sales quotations, sales orders, requests for
quotations and purchase orders) are supported as sources.
The conversion copies order items into delivery order items. Dates are copied
as appropriate, e.g. the C<transdate> field will be set to the current date.
Returns the new delivery order instance. The object returned is not
saved.
C<%params> can include the following options:
=over 2
=item C<items>
An optional array reference of RDBO instances for the items to use. If
missing then the method C<items_sorted> will be called on
C<$source>. This option can be used to override the sorting, to
exclude certain positions or to add additional ones.
=item C<skip_items_negative_qty>
If trueish then items with a negative quantity are skipped. Items with
a quantity of 0 are not affected by this option.
=item C<skip_items_zero_qty>
If trueish then items with a quantity of 0 are skipped.
=item C<item_filter>
An optional code reference that is called for each item with the item
as its sole parameter. Items for which the code reference returns a
falsish value will be skipped.
=item C<attributes>
An optional hash reference. If it exists then it is passed to C<new>
allowing the caller to set certain attributes for the new delivery
order.
=back
=item C<new_from_time_recordings $sources, %params>
Creates a new C<SL::DB::DeliveryOrder> instance from the time recordings
given as C<$sources>. All time recording entries must belong to the same
customer. Time recordings are sorted by article and date. For each article
a new delivery order item is created. If no article is associated with an
entry, a default article will be used. The article given in the time
recording entry can be overriden.
Entries of the same date (for each article) are summed together and form a
list entry in the long description of the item.
The created delivery order object will be returnd but not saved.
C<$sources> must be an array reference of C<SL::DB::TimeRecording> instances.
C<%params> can include the following options:
=over 2
=item C<attributes>
An optional hash reference. If it exists then it is used to set
attributes of the newly created delivery order object.
=item C<default_part_id>
An optional part id which is used as default value if no part is set
in the time recording entry.
=item C<default_partnumber>
Like C<default_part_id> but given as partnumber, not as id.
=item C<override_part_id>
An optional part id which is used instead of a value set in the time
recording entry.
=item C<override_partnumber>
Like C<overrride_part_id> but given as partnumber, not as id.
=item C<related_order>
An optional C<SL::DB::Order> object. If it exists then it is used to
generate the delivery order from that via C<new_from>.
The generated items are created from a suitable item of the related
order. If no suitable item is found, an exception is thrown.
=item C<rounding>
An optional boolean value. If truish, then the durations of the time entries
are rounded up to the full quarters of an hour.
=back
=item C<sales_order>
TODO: Describe sales_order
=item C<type>
Returns a string describing this record's type: either
C<sales_delivery_order> or C<purchase_delivery_order>.
=item C<convert_to_invoice %params>
Creates a new invoice with C<$self> as the basis by calling
L<SL::DB::Invoice::new_from>. That invoice is posted, and C<$self> is
linked to the new invoice via L<SL::DB::RecordLink>. C<$self>'s
C<closed> attribute is set to C<true>, and C<$self> is saved.
The arguments in C<%params> are passed to L<SL::DB::Invoice::new_from>.
Returns the new invoice instance on success and C<undef> on
failure. The whole process is run inside a transaction. On failure
nothing is created or changed in the database.
At the moment only sales delivery orders can be converted.
=back
=head1 BUGS
Nothing here yet.
=head1 AUTHOR
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
=cut
« Zurück
1
…
43
44
45
46
47
…
154
Weiter »
(45-45/154)
Lade...