summaryrefslogtreecommitdiff
path: root/scripts/inventory.pl
blob: 8bab9f92e156a922a411d38908d1a66b3601f4d0 (plain)
  1. =pod
  2. =head1 NAME
  3. LedgerSMB::Scripts::inventory - LedgerSMB class defining the Controller
  4. functions, template instantiation and rendering for inventory management.
  5. =head1 SYOPSIS
  6. This module is the UI controller for the customer DB access; it provides the
  7. View interface, as well as defines the Save customer.
  8. Save customer will update or create as needed.
  9. =head1 METHODS
  10. =cut
  11. package LedgerSMB::Scripts::customer;
  12. use LedgerSMB::Template;
  13. use LedgerSMB::DBObject::Customer;
  14. #require 'lsmb-request.pl';
  15. =over
  16. =item begin_adjust
  17. This entry point specifies the screen for setting up an inventory adjustment.
  18. =back
  19. =cut
  20. sub begin_adjust {
  21. my ($request) = @_;
  22. my $template = LedgerSMB::Template->new(
  23. user => $request->{_user},
  24. template => 'adjustment_setup',
  25. locale => $request->{_locale},
  26. path => 'UI/inventory',
  27. format => 'HTML'
  28. );
  29. $template->render($request);
  30. }
  31. =over
  32. =item enter_adjust
  33. This entry point specifies the screen for entering an inventory adjustment.
  34. =back
  35. =cut
  36. sub enter_adjust {
  37. my ($request) = @_;
  38. my $adjustment = LedgerSMB::DBObject::Inventory->new(base => $request);
  39. my $template = LedgerSMB::Template->new(
  40. user => $request->{_user},
  41. template => 'adjustment_entry',
  42. locale => $request->{_locale},
  43. path => 'UI/inventory',
  44. format => 'HTML'
  45. );
  46. $template->render($adjustment);
  47. }
  48. =over
  49. =item adjustment_next
  50. This function is triggered on the next button on the adjustment entry screen.
  51. It retrieves inventory information, calculates adjustment values, and displays the
  52. screen.
  53. =back
  54. =cut
  55. sub adjustment_next {
  56. my ($request) = @_;
  57. my $adjustment = LedgerSMB::DBObject::Inventory->new(base => $request);
  58. for my $i (1 .. $adjustment->{rowcount}){
  59. if ($adjustment->{"row_$i"} eq "new"){
  60. my $item = $adjustment->retrieve_item_at_date(
  61. $adjustment->{"partnumber_new_$i"});
  62. $adjustment->{"row_$i"} = $item->{id};
  63. $adjustment->{"description_$i"} = $item->{description};
  64. $adjustment->{"onhand_$i"} = $item->{onhand};
  65. }
  66. $adjustment->{"qty_$i"} = $adjustment->{"onhand_$i"}
  67. - $adjustment->{"counted_$i"};
  68. }
  69. ++$adjustment->{rowcount};
  70. enter_adjust($adjustment);
  71. }
  72. =over
  73. =item adjustment_save
  74. This function saves the inventory adjustment report and then creates the required
  75. invoices.
  76. =back
  77. =cut
  78. sub adjustment_save {
  79. my ($request) = @_;
  80. my $adjustment = LedgerSMB::DBObject::Inventory->new(base => $request);
  81. $adjustment->save;
  82. begin_adjust($request);
  83. }
  84. 1;