Revision 5ef1fa84
Von Bernd Bleßmann vor mehr als 8 Jahren hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
57 | 57 |
# actions |
58 | 58 |
# |
59 | 59 |
|
60 |
# add a new order |
|
60 | 61 |
sub action_add { |
61 | 62 |
my ($self) = @_; |
62 | 63 |
|
... | ... | |
73 | 74 |
); |
74 | 75 |
} |
75 | 76 |
|
77 |
# edit an existing order |
|
76 | 78 |
sub action_edit { |
77 | 79 |
my ($self) = @_; |
78 | 80 |
|
... | ... | |
88 | 90 |
); |
89 | 91 |
} |
90 | 92 |
|
93 |
# delete the order |
|
91 | 94 |
sub action_delete { |
92 | 95 |
my ($self) = @_; |
93 | 96 |
|
... | ... | |
107 | 110 |
$self->redirect_to(@redirect_params); |
108 | 111 |
} |
109 | 112 |
|
113 |
# save the order |
|
110 | 114 |
sub action_save { |
111 | 115 |
my ($self) = @_; |
112 | 116 |
|
... | ... | |
127 | 131 |
$self->redirect_to(@redirect_params); |
128 | 132 |
} |
129 | 133 |
|
134 |
# print the order |
|
135 |
# |
|
136 |
# This is called if "print" is pressed in the print dialog. |
|
137 |
# If PDF creation was requested and succeeded, the pdf is stored in a session |
|
138 |
# file and the filename is stored as session value with an unique key. A |
|
139 |
# javascript function with this key is then called. This function calls the |
|
140 |
# download action below (action_download_pdf), which offers the file for |
|
141 |
# download. |
|
130 | 142 |
sub action_print { |
131 | 143 |
my ($self) = @_; |
132 | 144 |
|
... | ... | |
211 | 223 |
$self->js->render; |
212 | 224 |
} |
213 | 225 |
|
226 |
# offer pdf for download |
|
227 |
# |
|
228 |
# It needs to get the key for the session value to get the pdf file. |
|
214 | 229 |
sub action_download_pdf { |
215 | 230 |
my ($self) = @_; |
216 | 231 |
|
... | ... | |
223 | 238 |
); |
224 | 239 |
} |
225 | 240 |
|
241 |
# open the email dialog |
|
226 | 242 |
sub action_show_email_dialog { |
227 | 243 |
my ($self) = @_; |
228 | 244 |
|
... | ... | |
257 | 273 |
->render($self); |
258 | 274 |
} |
259 | 275 |
|
276 |
# send email |
|
277 |
# |
|
260 | 278 |
# Todo: handling error messages: flash is not displayed in dialog, but in the main form |
261 | 279 |
sub action_send_email { |
262 | 280 |
my ($self) = @_; |
... | ... | |
296 | 314 |
->render($self); |
297 | 315 |
} |
298 | 316 |
|
317 |
# save the order and redirect to the frontend subroutine for a new |
|
318 |
# delivery order |
|
299 | 319 |
sub action_save_and_delivery_order { |
300 | 320 |
my ($self) = @_; |
301 | 321 |
|
... | ... | |
316 | 336 |
$self->redirect_to(@redirect_params); |
317 | 337 |
} |
318 | 338 |
|
339 |
# set form elements in respect of a changed customer or vendor |
|
340 |
# |
|
341 |
# This action is called on an change of the customer/vendor picker. |
|
319 | 342 |
sub action_customer_vendor_changed { |
320 | 343 |
my ($self) = @_; |
321 | 344 |
|
... | ... | |
360 | 383 |
$self->js->render(); |
361 | 384 |
} |
362 | 385 |
|
386 |
# called if a unit in an existing item row is changed |
|
363 | 387 |
sub action_unit_changed { |
364 | 388 |
my ($self) = @_; |
365 | 389 |
|
... | ... | |
378 | 402 |
$self->js->render(); |
379 | 403 |
} |
380 | 404 |
|
405 |
# add an item row for a new item entered in the input row |
|
381 | 406 |
sub action_add_item { |
382 | 407 |
my ($self) = @_; |
383 | 408 |
|
... | ... | |
409 | 434 |
$self->js->render(); |
410 | 435 |
} |
411 | 436 |
|
437 |
# open the dialog for entering multiple items at once |
|
412 | 438 |
sub action_show_multi_items_dialog { |
413 | 439 |
require SL::DB::PartsGroup; |
414 | 440 |
$_[0]->render('order/tabs/_multi_items_dialog', { layout => 0 }, |
415 | 441 |
all_partsgroups => SL::DB::Manager::PartsGroup->get_all); |
416 | 442 |
} |
417 | 443 |
|
444 |
# update the filter results in the multi item dialog |
|
418 | 445 |
sub action_multi_items_update_result { |
419 | 446 |
my $max_count = 100; |
420 | 447 |
|
... | ... | |
435 | 462 |
} |
436 | 463 |
} |
437 | 464 |
|
465 |
# add item rows for multiple items add once |
|
438 | 466 |
sub action_add_multi_items { |
439 | 467 |
my ($self) = @_; |
440 | 468 |
|
... | ... | |
471 | 499 |
$self->js->render(); |
472 | 500 |
} |
473 | 501 |
|
502 |
# recalculate all linetotals, amounts and taxes and redisplay them |
|
474 | 503 |
sub action_recalc_amounts_and_taxes { |
475 | 504 |
my ($self) = @_; |
476 | 505 |
|
... | ... | |
481 | 510 |
$self->js->render(); |
482 | 511 |
} |
483 | 512 |
|
513 |
# redisplay item rows if the are sorted by an attribute |
|
484 | 514 |
sub action_reorder_items { |
485 | 515 |
my ($self) = @_; |
486 | 516 |
|
... | ... | |
504 | 534 |
->render; |
505 | 535 |
} |
506 | 536 |
|
537 |
# show the popup to choose a price/discount source |
|
507 | 538 |
sub action_price_popup { |
508 | 539 |
my ($self) = @_; |
509 | 540 |
|
... | ... | |
513 | 544 |
$self->render_price_dialog($item); |
514 | 545 |
} |
515 | 546 |
|
547 |
# get the longdescription for an item if the dialog to enter/change the |
|
548 |
# longdescription was opened and the longdescription is empty |
|
549 |
# |
|
550 |
# If this item is new, get the longdescription from Part. |
|
551 |
# Get it from OrderItem else. |
|
516 | 552 |
sub action_get_item_longdescription { |
517 | 553 |
my $longdescription; |
518 | 554 |
|
... | ... | |
524 | 560 |
$_[0]->render(\ $longdescription, { type => 'text' }); |
525 | 561 |
} |
526 | 562 |
|
527 |
|
|
528 | 563 |
sub _js_redisplay_linetotals { |
529 | 564 |
my ($self) = @_; |
530 | 565 |
|
... | ... | |
591 | 626 |
$_[0]->_make_order; |
592 | 627 |
} |
593 | 628 |
|
629 |
# model used to filter/display the parts in the multi-items dialog |
|
594 | 630 |
sub init_multi_items_models { |
595 | 631 |
SL::Controller::Helper::GetModels->new( |
596 | 632 |
controller => $_[0], |
... | ... | |
623 | 659 |
$::auth->assert($right); |
624 | 660 |
} |
625 | 661 |
|
662 |
# build the selection box for contacts |
|
663 |
# |
|
664 |
# Needed, if customer/vendor changed. |
|
626 | 665 |
sub build_contact_select { |
627 | 666 |
my ($self) = @_; |
628 | 667 |
|
... | ... | |
635 | 674 |
); |
636 | 675 |
} |
637 | 676 |
|
677 |
# build the selection box for shiptos |
|
678 |
# |
|
679 |
# Needed, if customer/vendor changed. |
|
638 | 680 |
sub build_shipto_select { |
639 | 681 |
my ($self) = @_; |
640 | 682 |
|
... | ... | |
647 | 689 |
); |
648 | 690 |
} |
649 | 691 |
|
692 |
# build the rows for displaying taxes |
|
693 |
# |
|
694 |
# Called if amounts where recalculated and redisplayed. |
|
650 | 695 |
sub build_tax_rows { |
651 | 696 |
my ($self) = @_; |
652 | 697 |
|
... | ... | |
687 | 732 |
$self->order(SL::DB::Manager::Order->find_by(id => $::form->{id})); |
688 | 733 |
} |
689 | 734 |
|
735 |
# load or create a new order object |
|
736 |
# |
|
737 |
# And assign changes from the for to this object. |
|
738 |
# If the order is loaded from db, check if items are deleted in the form, |
|
739 |
# remove them form the object and collect them for removing from db on saving. |
|
740 |
# Then create/update items from form (via _make_item) and add them. |
|
690 | 741 |
sub _make_order { |
691 | 742 |
my ($self) = @_; |
692 | 743 |
|
... | ... | |
723 | 774 |
return $order; |
724 | 775 |
} |
725 | 776 |
|
726 |
|
|
777 |
# create or update items from form |
|
778 |
# |
|
727 | 779 |
# Make item objects from form values. For items already existing read from db. |
728 | 780 |
# Create a new item else. And assign attributes. |
729 | 781 |
sub _make_item { |
... | ... | |
745 | 797 |
return $item; |
746 | 798 |
} |
747 | 799 |
|
800 |
# create a new item |
|
801 |
# |
|
802 |
# This is used to add one (or more) items |
|
748 | 803 |
sub _new_item { |
749 | 804 |
my ($record, $attr) = @_; |
750 | 805 |
|
... | ... | |
800 | 855 |
return $item; |
801 | 856 |
} |
802 | 857 |
|
858 |
# recalculate prices and taxes |
|
859 |
# |
|
860 |
# Using the PriceTaxCalclulator. Store linetotals in the item objects. |
|
803 | 861 |
sub _recalc { |
804 | 862 |
my ($self) = @_; |
805 | 863 |
|
... | ... | |
820 | 878 |
pairwise { $a->{linetotal} = $b->{linetotal} } @{$self->order->items}, @{$pat{items}}; |
821 | 879 |
} |
822 | 880 |
|
823 |
|
|
881 |
# get data for saving, printing, ..., that is not changed in the form |
|
882 |
# |
|
883 |
# Only cvars for now. |
|
824 | 884 |
sub _get_unalterable_data { |
825 | 885 |
my ($self) = @_; |
826 | 886 |
|
... | ... | |
834 | 894 |
} |
835 | 895 |
} |
836 | 896 |
|
837 |
|
|
897 |
# delete the order |
|
898 |
# |
|
899 |
# And remove related files in the spool directory |
|
838 | 900 |
sub _delete { |
839 | 901 |
my ($self) = @_; |
840 | 902 |
|
... | ... | |
854 | 916 |
return $errors; |
855 | 917 |
} |
856 | 918 |
|
857 |
|
|
919 |
# save the order |
|
920 |
# |
|
921 |
# And delete items that are deleted in the form. |
|
858 | 922 |
sub _save { |
859 | 923 |
my ($self) = @_; |
860 | 924 |
|
... | ... | |
995 | 1059 |
|
996 | 1060 |
SL::Controller::Order - controller for orders |
997 | 1061 |
|
1062 |
=head1 SYNOPSIS |
|
1063 |
|
|
1064 |
This is a new form to enter orders, completely rewritten with the use |
|
1065 |
of controller and java script techniques. |
|
1066 |
|
|
1067 |
The aim is to provide the user a better expirience and a faster flow |
|
1068 |
of work. Also the code should be more readable, more reliable and |
|
1069 |
better to maintain. |
|
1070 |
|
|
1071 |
=head2 key features |
|
1072 |
|
|
1073 |
=over 2 |
|
1074 |
|
|
1075 |
=item * |
|
1076 |
One input row, so that input happens every time at the same place. |
|
1077 |
|
|
1078 |
=item * |
|
1079 |
Use of pickers where possible. |
|
1080 |
|
|
1081 |
=item * |
|
1082 |
Possibility to enter more than one item at once. |
|
1083 |
|
|
1084 |
=item * |
|
1085 |
Save order only on "save" (and "save and delivery order"-workflow). No |
|
1086 |
hidden save on "print" or "email". |
|
1087 |
|
|
1088 |
=item * |
|
1089 |
Item list in a scrollable area, so that the workflow buttons stay at |
|
1090 |
the bottom. |
|
1091 |
|
|
1092 |
=item * |
|
1093 |
Reordering item rows with drag and drop is possible. Sorting item rows is |
|
1094 |
possible (by partnumber, description, qty, sellprice and discount for now). |
|
1095 |
|
|
1096 |
=item * |
|
1097 |
No "update" is necessary. All entries and calculations are managed |
|
1098 |
with ajax-calls and the page does only reload on "save". |
|
1099 |
|
|
1100 |
=item * |
|
1101 |
User can see changes immediately, because of the use of java script |
|
1102 |
and ajax. |
|
1103 |
|
|
1104 |
=back |
|
1105 |
|
|
1106 |
=head1 CODE |
|
1107 |
|
|
1108 |
=head2 layout |
|
1109 |
|
|
1110 |
=over 2 |
|
1111 |
|
|
1112 |
=item * |
|
1113 |
SL/Controller/Order.pm: the controller |
|
1114 |
|
|
1115 |
=item * |
|
1116 |
template/webpages/order/form.html: main form |
|
1117 |
|
|
1118 |
=item * |
|
1119 |
template/webpages/order/tabs/basic_data.html: main tab for basic_data |
|
1120 |
|
|
1121 |
This is the only tab here for now. "linked records" and "webdav" tabs are reused |
|
1122 |
from generic code. |
|
1123 |
|
|
1124 |
=over 3 |
|
1125 |
|
|
1126 |
=item * |
|
1127 |
template/webpages/order/tabs/_item_input.html: the input line for items |
|
1128 |
|
|
1129 |
=item * |
|
1130 |
template/webpages/order/tabs/_row.html: one row for already entered items |
|
1131 |
|
|
1132 |
=item * |
|
1133 |
template/webpages/order/tabs/_tax_row.html: displaying tax information |
|
1134 |
|
|
1135 |
=item * |
|
1136 |
template/webpages/order/tabs/_multi_items_dialog.html: dialog for entering more |
|
1137 |
than one item at once |
|
1138 |
|
|
1139 |
=item * |
|
1140 |
template/webpages/order/tabs/_multi_items_result.html: results for the filter in |
|
1141 |
the multi items dialog |
|
1142 |
|
|
1143 |
=item * |
|
1144 |
template/webpages/order/tabs/_price_sources_dialog.html: dialog for selecting |
|
1145 |
price and discount sources |
|
1146 |
|
|
1147 |
=item * |
|
1148 |
template/webpages/order/tabs/_email_dialog.html: email dialog |
|
1149 |
|
|
1150 |
=back |
|
1151 |
|
|
1152 |
=item * |
|
1153 |
js/kivi.Order.js: java script functions |
|
1154 |
|
|
1155 |
=back |
|
1156 |
|
|
998 | 1157 |
=head1 TODO |
999 | 1158 |
|
1000 | 1159 |
=over 2 |
Auch abrufbar als: Unified diff
Auftrags-Controller: Doku und Kommentare