summaryrefslogtreecommitdiff
path: root/scripts/vendor.pl
blob: 6fa2cf77048a0f79d18938272fdadec71b0a4734 (plain)
  1. #!/usr/bin/perl
  2. =pod
  3. =head1 NAME
  4. LedgerSMB::Scripts::vendor - LedgerSMB class defining the Controller
  5. functions, template instantiation and rendering for vendor editing and display.
  6. =head1 SYOPSIS
  7. This module is the UI controller for the vendor DB access; it provides the
  8. View interface, as well as defines the Save vendor.
  9. Save vendor will update or create as needed.
  10. =head1 METHODS
  11. =cut
  12. package LedgerSMB::Scripts::vendor;
  13. use LedgerSMB::Template;
  14. use LedgerSMB::DBObject::Vendor;
  15. require 'lsmb-request.pl';
  16. =pod
  17. =over
  18. =item get($self, $request, $user)
  19. Requires form var: id
  20. Extracts a single vendor from the database, using its company ID as the primary
  21. point of uniqueness. Shows (appropriate to user privileges) and allows editing
  22. of the vendor informations.
  23. =back
  24. =cut
  25. sub get {
  26. my ($request) = @_;
  27. my $vendor = LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
  28. $vendor->set( entity_class=> '1' );
  29. my $result = $vendor->get();
  30. my $template = LedgerSMB::Template->new( user => $user,
  31. template => 'contact', language => $user->{language},
  32. path => 'UI/Contact',
  33. format => 'HTML');
  34. $template->render($results);
  35. }
  36. sub add_location {
  37. my ($request) = @_;
  38. my $vendor= LedgerSMB::DBObject::Vendor->new({base => $request, copy => 'all'});
  39. $vendor->set( entity_class=> '1' );
  40. $vendor->save_location();
  41. $vendor->get();
  42. $vendor->get_metadata();
  43. _render_main_screen($vendor);
  44. }
  45. =pod
  46. =over
  47. =item add
  48. This method creates a blank screen for entering a vendor's information.
  49. =back
  50. =cut
  51. sub add {
  52. my ($request) = @_;
  53. my $vendor= LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
  54. $vendor->set( entity_class=> '1' );
  55. _render_main_screen($vendor);
  56. }
  57. =pod
  58. =over
  59. =item search($self, $request, $user)
  60. Requires form var: search_pattern
  61. Directly calls the database function search, and returns a set of all vendors
  62. found that match the search parameters. Search parameters search over address
  63. as well as vendor/Company name.
  64. =back
  65. =cut
  66. sub search {
  67. my ($request) = @_;
  68. if ($request->type() eq 'POST') {
  69. # assume it's asking us to do the search, now
  70. my $vendor = LedgerSMB::DBObject::Vendor->new(base => $request, copy => 'all');
  71. $vendor->set(entity_class=>1);
  72. my $results = $vendor->search($vendor->{search_pattern});
  73. my $template = LedgerSMB::Template->new( user => $user,
  74. template => 'Contact/vendor', language => $user->{language},
  75. format => 'HTML');
  76. $template->render($results);
  77. }
  78. else {
  79. # grab the happy search page out.
  80. my $template = LedgerSMB::Template->new(
  81. user => $user,
  82. path => 'UI/Contact' ,
  83. template => 'vendor_search',
  84. locale => $request->{_locale},
  85. format => 'HTML');
  86. $template->render();
  87. }
  88. }
  89. =pod
  90. =over
  91. =item save($self, $request, $user)
  92. Saves a vendor to the database. The function will update or insert a new
  93. vendor as needed, and will generate a new Company ID for the vendor if needed.
  94. =back
  95. =cut
  96. sub save {
  97. my ($request) = @_;
  98. my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
  99. $vendor->save();
  100. _render_main_screen($vendor);
  101. }
  102. sub edit{
  103. my $request = shift @_;
  104. my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
  105. $vendor->get();
  106. _render_main_screen($vendor);
  107. }
  108. sub _render_main_screen{
  109. my $vendor = shift @_;
  110. $vendor->get_metadata();
  111. $vendor->{creditlimit} = "$vendor->{creditlimit}";
  112. $vendor->{discount} = "$vendor->{discount}";
  113. $vendor->{script} = "vendor.pl";
  114. my $template = LedgerSMB::Template->new(
  115. user => $vendor->{_user},
  116. template => 'contact',
  117. locale => $vendor->{_locale},
  118. path => 'UI/Contact',
  119. format => 'HTML'
  120. );
  121. $template->render($vendor);
  122. }
  123. sub save_contact {
  124. my ($request) = @_;
  125. my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
  126. $vendor->save_contact();
  127. $vendor->get;
  128. _render_main_screen($vendor );
  129. }
  130. sub save_bank_account {
  131. my ($request) = @_;
  132. my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
  133. $vendor->save_bank_account();
  134. $vendor->get;
  135. _render_main_screen($vendor );
  136. }
  137. sub save_notes {
  138. my ($request) = @_;
  139. my $vendor = LedgerSMB::DBObject::Vendor->new({base => $request});
  140. $vendor->save_notes();
  141. $vendor->get();
  142. _render_main_screen($vendor );
  143. }
  144. 1;